How can I set up a WPF control to fill the available space in its parent's container, but not expand the parent?
The following snippet describes the layout I am attempting. I would like the Grid
to stretch to accommodate the Expander
, and I would like the ListBox
only to fill the Grid
. I want the ListBox
's scroll bar to appear when the Grid
is too small to show all the ListBoxItem
s.
<ScrollViewer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<ListBox Grid.Row="0" Grid.Column="0" />
<Expander Grid.Row="0" Grid.Column="1" Header="Expander" />
</Grid>
</ScrollViewer>
Currently what happens is that the Grid
stretches to fit the entire ListBox
, and the outer ScrollViewer
's vertical scroll bar appears. I only want the outer scroll bar to appear when the Expander
gets too big to fit on screen.