WPF grid size

This question is hard to describe succinctly, so bear with me.

I currently have a two-row grid. The height of the first line is Auto, and the second line height is *, so when I resize the window, the second line grows and shrinks depending on the window.

This is the main layout:

<Window>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Border>
            ...
        </Border>
        <Border Grid.Row="2">
            ...
        </Border>
    </Grid>
</Window>

Here is a bad outline of the existing behavior:

____    ____    ____
     ->      ->
____    ____    ____
                ____
        ____
____

I would like to add some “minimum height” to the second line, so when I change the window size a bit, the second line will stop shrinking and the first line will start shrinking.

Desired behavior:

____    ____    ____
     ->      -> ____
____    ____
                ____
        ____
____

Is there an easy way to get the minimum height for the second row and force the first to be compressed?

More details:

When I set MinHeight in the second row, it just pinches the grid when I resize it below this size.

, . , MaxHeight, Auto height.

. , , .

+5
1

, . , MaxHeight, Auto height.

, , , . MaxHeight :

<Grid.RowDefinitions>
    <RowDefinition Height="*" MaxHeight="{Binding MyProperty}"/>
    <RowDefinition Height="*" MinHeight="100"/>
</Grid.RowDefinitions>

: , . , , , :

<Grid ShowGridLines="True" Name="myGrid">
    <Grid.Resources>
        <local:RowHeightConverter x:Key="rowHeightConverter" />
    </Grid.Resources>
    <Grid.RowDefinitions>
        <RowDefinition Name="row1" MaxHeight="{Binding MyProperty}">
            <RowDefinition.Height>
                <MultiBinding Converter="{StaticResource rowHeightConverter}">
                    <Binding Path="ActualHeight" ElementName="row2" />
                    <Binding Path="ActualHeight" ElementName="myGrid" />
                    <Binding Path="MaxHeight" ElementName="row1" />
                </MultiBinding>
            </RowDefinition.Height>
        </RowDefinition>
        <RowDefinition Name="row2" Height="*" MinHeight="300"/>
    </Grid.RowDefinitions>
</Grid>

:

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    double row2Height = (double)values[0];
    double gridHeight = (double)values[1];
    double row1MaxHeight = (double)values[2];

    if (gridHeight - row2Height >= row1MaxHeight)
    {
        return gridHeight - row2Height;
    }

    return row1MaxHeight;
}
+7

All Articles