结合自动和*

时间:2012-09-12 12:40:33

标签: wpf xaml

让我们假设我有3列网格:

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

所需总高度为600.如果可用空间为900像素,那么额外的300像素应在列间平均分配,因此最终结果为:

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

如果我使用*来设置高度,那么最终结果是每列300像素,这不是我想要的。基本上我需要auto和*的组合。这可以在xaml中完成吗?

2 个答案:

答案 0 :(得分:1)

试试这个:

<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>

您将看到高度至少为100,200,300,但是只要有足够的位置,额外的位置将平均分配到行。

答案 1 :(得分:0)

第一个col高度= 2 *

第二个col高= 3 *

第3个col高= 4 *