Given the XAML below, is it possible to make an adjustment so that when either of the Expander
items are expanded, the TextBlock
content stretches vertically to fill the remaining space? (Note that this XAML is purposely simplified, the solution must satisfy this simple example and any data bound ItemsSource
scenario).
The StackPanel
itself stretches to fill the space (since it is contained within a Grid
), so I assume there is a conflict within the StackPanel
measuring code that does not allow infinitely large content elements. I'm not even sure if this is possible to resolve elegantly, it may just require manually overriding the measuring code and determining the optimal expanded height for the content container.
<Grid>
<StackPanel>
<Expander Header="Item 1">
<TextBlock Background="LightCoral" Text="Content 1 should be stretched vertically when expanded"/>
</Expander>
<Expander Header="Item 2">
<TextBlock Background="LightBlue" Text="Content 2 should be stretched vertically when expanded"/>
</Expander>
</StackPanel>
</Grid>
NOTE: I read through How to get StackPanel's children to fill maximum space downward? and it is not really related to this question as the solution to that post is to use a DockPanel
which is not possible in a data bound ItemsSource
scenario.