Goran
Goran

Reputation: 6518

Combining Auto and *

Lets assume that I have grid with 3 columns:

1st column requires minimum height of 100 to display its content
2nd column requires minimum height of 200 to display its content
3rd column requires minimum height of 300 to display its content

Total required height is 600. If available space is 900 pixels, then extra 300 pixels should be equally split amongst columns, so the final result is:

1st column height = 200
2nd column height = 300
3rd column height = 400

if I use * for setting height, then the final result is each column 300 pixels, which is not what I want. Basically I need a combination of auto and *. Can this be done in xaml?

Upvotes: 1

Views: 231

Answers (2)

Steve B
Steve B

Reputation: 37690

Try this :

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"
        Height="800"
        Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"
                           MinHeight="100" />
            <RowDefinition Height="*"
                           MinHeight="200" />
            <RowDefinition Height="*"
                           MinHeight="300" />
        </Grid.RowDefinitions>
        <TextBlock  Background="LightBlue"
                    Text="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}" />
        <TextBlock Grid.Row="1"
                   Background="LightCyan"
                   Text="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}" />
        <TextBlock Grid.Row="2"
                   Background="LightCoral"
                   Text="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}" />
    </Grid>
</Window>

You will see that the heights are at least 100, 200, 300, but as soon there is enough place, the extra place will be equally distributed to the rows.

Upvotes: 1

Mikl&#243;s Balogh
Mikl&#243;s Balogh

Reputation: 2202

1st col height=2*

2nd col height=3*

3rd col height=4*

Upvotes: 0

Related Questions