-2

I have a form with two Grid elements in a vertical StackPanel. I would have imagined the bottom Grid would automatically fill all available space, as I wish it to, but I have set heights on the Grid rows:

<RowDefinition Height="20" />
<RowDefinition Height="*" />
<RowDefinition Height="25" />

The short rows at the top and bottom are for labels and buttons, respectively. I have tried setting the grid's VerticallAllignment to Stretch, to no avail.

How do I anchor the bottom of the bottom grid to the bottom of the form, regardless of the form's height?

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • 2
    A vertical StackPanel never resizes its children vertically. Use an outer Grid with two rows or a DockPanel instead. – Clemens Nov 11 '16 at 08:32

1 Answers1

2

Essentially you can't use StackPanel to fill all available vertical space.

But you may use a DockPanel:

<DockPanel LastChildFill="True">
    <Grid DockPanel.Dock="Top"/>
    <Grid />
</DockPanel>

You may also use a Grid:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Grid Grid.Row="0"/>
    <Grid Grid.Row="1"/>
</Grid>
Clemens
  • 123,504
  • 12
  • 155
  • 268
A.N.
  • 108
  • 6