19

我有 3 行的网格布局。如何将第 3 行拆分为 2 列。

<Grid.RowDefinitions>
    <RowDefinition Height="0.75*"/>
    <RowDefinition Height="0.25*"/>
    <RowDefinition Height="36"/>
</Grid.RowDefinitions>
4

2 回答 2

41

有两种方法可以做到:

  • 使用嵌套布局。将另一个Grid放在第三行,并在该子网格中有两列。

    <Grid>
        <Grid.RowDefinitions> ... </Grid.RowDefinitions>
        <ThingInFirstRow Grid.Row="0" />
        <ThingInSecondRow Grid.Row="1" />
        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <ThingInLowerLeft Grid.Column="0" />
            <ThingInLowerRight Grid.Column="0" />
        </Grid>
    </Grid>
    
  • 坚持使用一个Grid,给它两列,并使用 . 使前两行中的内容跨越两列ColumnSpan

    <Grid>
        <Grid.RowDefinitions> ... </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <ThingInFirstRow Grid.Row="0" Grid.ColumnSpan="2" />
        <ThingInSecondRow Grid.Row="1" Grid.ColumnSpan="2" />
        <ThingInLowerLeft Grid.Row="2" Grid.Column="0" />
        <ThingInLowerRight Grid.Row="2" Grid.Column="1" />
    </Grid>
    
于 2012-01-27T21:56:53.357 回答
0
<Grid>
        <Grid.RowDefinitions >
            <RowDefinition Height="0.75"/>
            <RowDefinition Height="0.25"/>
            <RowDefinition Height="36"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>       
        </Grid>
</Grid>
于 2020-06-07T13:11:22.833 回答