为什么属性Height在以下上下文中具有值*?

时间:2014-11-20 05:18:53

标签: xaml windows-phone-8.1

我正在学习Windows Phone 8.1。在设计的过程中,我在网站上看到了一段类似的代码。

有人可以向我解释为什么属性Height被赋予一个值*而不是下一行中的任何数值吗?

<RowDefinition Height="*"></RowDefinition>

完整代码如下:

<Grid x:Name="myGrid">
      <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
      </Grid.RowDefinitions>                    
</Grid>

1 个答案:

答案 0 :(得分:2)

它被称为星大小(见docs)。它将按加权比例分配可用空间。

例如:

<Grid>
    <Grid.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="FontSize" Value="20" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>
    </Grid.Resources>

    <Grid.RowDefinitions>
        <RowDefinition Height="50" />
        <RowDefinition Height="*" />
        <RowDefinition Height="2*" />
        <RowDefinition Height="2*" />
    </Grid.RowDefinitions>

    <Border Grid.Row="0" Background="Red">
        <TextBlock>I'm 50px tall</TextBlock>
    </Border>
    <Border Grid.Row="1" Background="Lime">
        <TextBlock>I get 20% of the remaining space</TextBlock>
    </Border>
    <Border Grid.Row="2" Background="Cyan">
        <TextBlock>I get 40% of the remaining space</TextBlock>
    </Border>
    <Border Grid.Row="3" Background="Yellow">
        <TextBlock>I get 40% of the remaining space</TextBlock>
    </Border>
</Grid>

Screenshot