Search code examples
wpforientationstackpanelfill

stretch bottom control in stackpanel


Only column headers are displayed for DataGrid. How to force the DataGrid to fill all remaining space of StackPanel? And how to force the StackPanel to fill all empty space of it's parent control? There is a lot of empty space below the DataGrid.

<StackPanel Orientation="Vertical">
<Label>some text</Label>
<DataGrid/>
</StackPanel>

I know how to solve this using Grid, but I don't want to use it for such simple layout.


Solution

  • StackPanels do not allow for this kind of layout, they just stack things, giving their children the amount of space they request (and not more). If you want something to stretch consider using a DockPanel (with LastChildFill= true) or a Grid. Also the StackPanel probably takes up all space, it just does not use it (you could for example set the StackPanel's Background to confirm that).