2

我正在用 C#(WPF) 编程。我使用 4 行网格,如下所示:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition>
        <RowDefinition>
        <RowDefinition>
        <RowDefinition>
    </Grid.RowDefinitions>

    <!-- Height of this row is related to its content -->
    <Grid Row="0">
    </Grid>

    <!-- Height of this row is related to its content -->
    <Grid Row="1">
    </Grid>

    <!-- Remaining of Height should be used here... -->
    <Grid Row="2">
    </Grid>

    <!-- Height of this row is related to its content and this row should be stick to bottom of page  -->
    <Grid Row="3">
    </Grid>

</Grid> 

根据我的 XAML 代码中的注释:

  • 在 Row=0 中,Height 与其内容有关
  • 在 Row=1 中,Height 与其内容有关
  • 在 Row=3 中,高度与它的内容有关,这一行应该贴在页面底部
  • 在 Row=2 中,此处应使用剩余高度

如何根据四个命名条件调整行定义?

更多想象请看这张图片: 在此处输入图像描述

4

1 回答 1

2

我现在不在 Windows 上,所以我无法测试它,但我会尝试这样的事情。

在您的 RowDefinition 中:

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

Height="Auto",表示该行将只占用其内容所需的高度。

Height="*",表示该行将占用所有剩余的可用高度。

于 2016-02-25T19:12:37.133 回答