I've spent two straight days on this and still can't figure it out! Please help!
What I want to do seems relatively simple. I have a window with a grid in it. There are three rows: one "Auto", one set to fill remaining space, and one set to "Auto" with a max height. Here is the xaml:
<Grid Name="theGrid" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto" MaxHeight="300"></RowDefinition>
</Grid.RowDefinitions>
<ContentControl Grid.Row="0" Content="{Binding fixedLabel}"></ContentControl>
<ContentControl Grid.Row="1" Content="{Binding bigLabel}"></ContentControl>
<ContentControl Grid.Row="2" Content="{Binding gridWithStackPanel}"></ContentControl>
</Grid>
The first two rows just have a simple label in them. The third row is itself made up of a grid. It is a simple grid with two rows, one allowed to fill the remaining space, and one marked "Auto". Here is the xaml for that grid:
<Grid Name="theGrid" Style="{StaticResource BasePGOGridStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<ContentControl Grid.Row="0" Content="{Binding stackPanel}"></ContentControl>
<ContentControl Grid.Row="1" Content="{Binding simpleLabel}"></ContentControl>
</Grid>
The desired behavior is simple: the second grid would have a stackpanel as its top item, with a simple label on the bottom. However, if the stackpanel has a lot of items, it just blows out the label on the bottom. Despite being set to "Auto", WPF doesn't seem to reserve the space for the 'simpleLabel'.
What seems to be happening is that WPF tells the second grid "Hey, you are marked down as 'Auto' in your parent grid, so take up as much space as you need". So, the second grid lays itself out as though it has lots of space, showing all of the items in the stackpanel. Then, WPF seems to say, "Wait a sec, there's a maxHeight value for your parent row, so you need to clip yourself". What ends up happening is that the 'simpleLabel' then gets cut out of the layout.
That's my best guess for what's happening, but maybe there is something else going on. I've done extensive research and can't find a solution to the problem. Am I really the only person ever putting a grid within a grid that has a MaxHeight? It seems like a basic part of WPF functionality.
Please let me know if you have any ideas!