Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand last grid row to fill window in wpf application

Tags:

c#

wpf

I have the following Grid setup in a WPF application.

  <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="220" />
            <RowDefinition Height="40" />
            <RowDefinition Height="80" />
            <RowDefinition Height="180*" />
        </Grid.RowDefinitions>
  <!-- some content -->
 </Grid>

What I want is for the final row to take up as much height as available in its parent. But it does not seem to honor my '*' command in the final row definition.

Please note that I want all other row heights to be fixed..

Is this possible? If so how? Any help or pointers are appreciated..

like image 237
Sharath Avatar asked Dec 15 '22 04:12

Sharath


2 Answers

place height="*" in last row.

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="220" />
        <RowDefinition Height="40" />
        <RowDefinition Height="80" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

like image 119
Ehsan Hafeez Avatar answered Jan 18 '23 23:01

Ehsan Hafeez


What you have written should be fine (though as @Bolu commented, the 180* could be replaced with * in this case). If the content in the last row is not expanding to fill the available size, I would suspect one of the following:

  1. The Grid may be nested somewhere below a layout panel that does not arrange its children to fill all available vertical space. For example, is one of the Grid panel's ancestors a StackPanel? A good way to test whether this is the culprit is to comment out the entire Grid and replace it with a Border with an easily distinguishable background (e.g., Magenta) and see if it occupies the entire area you expect the Grid to fill.

  2. There may not actually be any content in the last row. Did you set the correct Grid.Row value correctly?

  3. You may be overriding the layout behavior of the last row's content. Are you setting the content's VerticalAlignment to anything other than Stretch?

like image 39
Mike Strobel Avatar answered Jan 18 '23 23:01

Mike Strobel