I have a GroupBox (containing a ListBox) and an Expander, each in their own respective row within a Grid:
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Header="My List">
<ListBox>
...
</ListBox>
</GroupBox>
<Expander Grid.Row="1" ScrollViewer.CanContentScroll="True">
<Expander.Header>
<TextBlock FontWeight="Bold">My Expander</TextBlock>
</Expander.Header>
<StackPanel Margin="5 5 5 5">
<TextBlock TextWrapping="Wrap">
Lots<LineBreak />
and<LineBreak />
lots<LineBreak />
of<LineBreak />
lines.
</TextBlock>
<TextBlock TextWrapping="Wrap">
More <Run FontFamiliy="Courier">Stuff</Run> here.
</TextBlock>
</StackPanel>
</Expander>
<Grid>
Wanted behaviors:
I want the GroupBox (with the ListBox) to use all the available space for the Grid as defined by the parent (the parent being a Window for example) minus the size of the (closed) Expander. If the user opens up the Expander, it should let the GroupBox shrink (even collapse completely) and give space for the Expander.
However, I want to limit the height of the Expander to the maximum available height that the Grid is allowed to expand without causing overflows. If the Expander will therefore be limited in its height, it should start showing a vertical scrollbar.
Current behavior:
With my current XAML code, the Expander will make the Grid overflow, i.e. it will expand beyond the available space (and will therefore also not show a vertical scrollbar.)
Question in a nutshell:
How do I have to setup the Grid so that the Expander will be limited in its height to the maximum available height of the Grid?