Randy Minder
Randy Minder

Reputation: 48522

WPF - Need help with Grid Row Heights

In my window, I have a grid with two rows. In the first row I have a tab control. In the second row I have a row of buttons. I would like the second row to have a height of roughly 30. I would like the first row to consume the rest of the available height.

As the user resizes the grid vertically, I would like the second row to stay fixed at 30 and move with the vertical resize. I would like the first row to shrink or grow in proportion to the vertical resize.

As an example, say my window has an initial height of 800. My second row would be fixed at 30 and my first row would consume the difference (~770). Now say the user resizes the window vertically and decreases the total height to 600. I still want to see all my second row at 30, but my first row would shrink to ~570.

What do I set my grid row definitions at to accomplish this? I cannot seem to get it right.

Upvotes: 3

Views: 3970

Answers (3)

Jerry Joyce
Jerry Joyce

Reputation: 351

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

Upvotes: 1

decyclone
decyclone

Reputation: 30840

Set height of second row to 30 and height of first row to *.

Also, instead of fixed height for second row, use Auto to allocate auto height.

Also, learn the star sizing of grid in WPF.

Upvotes: 3

Andrei Pana
Andrei Pana

Reputation: 4502

Set first row's height to "*" (in xaml) and the second row's height to "30".

Upvotes: 3

Related Questions