Wpf nesting containers

柔情痞子 提交于 2020-01-07 04:43:11

问题


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?


回答1:


StackPanel does not stretch vertically.

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 ;) )

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


来源:https://stackoverflow.com/questions/4553568/wpf-nesting-containers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!