Wpf 嵌套容器 [英] Wpf nesting containers

查看:26
本文介绍了Wpf 嵌套容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在窗口控件上,我的主要容器是一个网格.
我的网格有 2 行,一行定义为 50*,另一行定义为 250*.
现在我想添加一个右侧边栏,比如说使用 StackPanel.
我想在 StackPanel 中有一个与 50* 网格行对齐的 ListBox,这样随着窗口高度变大,ListBox 大小也会变大.
我的问题是,当 ListBox 位于 StackPanel 内(嵌套在网格内)时,我是否可以实现这种行为,还是必须将 ListBox 直接放置在网格内?

On a window control, my main container is a grid.
My grid has 2 rows, one row definition is 50*, and the other is 250*.
Now i want to add a right sidebar, lets say with a StackPanel.
I would like to have a ListBox inside the StackPanel that aligns with the 50* grid row, so as the window height gets bigger, the ListBox size will also get bigger.
My question is whether i can achieve this behavior while the ListBox is inside the StackPanel (which is nested inside the grid) or must the ListBox be placed directly inside the grid?

推荐答案

StackPanel 不会垂直拉伸.

如果您必须需要一个包装父容器,请使用 Grid,它将向所有方向扩展(当然,如果您单独保留 Horizo​​ntal- 和 VerticalAlignment ;))

If you must need a wrapping parent container, use a Grid, which will expand in all directions (if you leave the Horizontal- and VerticalAlignment alone of course ;) )

另请查看 MSDN 上的面板概览.

Also check out the Panel Overview on MSDN.

Panel Name       x-Dimension             y-Dimension


- Canvas         Constrained to content     Constrained to content
- DockPanel      Constrained             Constrained
- StackPanel     Constrained             Constrained to content
  (Vertical Orientation)    
- StackPanel     Constrained to content  Constrained 
  (Horizontal Orientation)  
- Grid        Constrained             Constrained, except in cases where Auto apply to rows and columns
- WrapPanel      Constrained to content  Constrained to content

这篇关于Wpf 嵌套容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆