问题
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