在列格线中定义行格线

本文关键字:定义 | 更新日期: 2023-09-27 18:27:34

我有一个包含3个已定义列的网格。有没有一种方法可以在不影响其他2列的情况下将列1划分为3个网格行?我尝试过定义RowDefinitions,但它跨越了所有3列。我不想那样。我只希望它影响1列。

在列格线中定义行格线

不,不能。如果在Grid内部声明一个Row,那么它将用于所有的Columns

您可以做的一件事是在第一个Column中声明一个Grid,并在该Grid 中定义三行

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
   <Grid Grid.Column="0">
        <Grid.RowDefinitions>
             <RowDefinition/>
             <RowDefinition/>
             <RowDefinition/>
        </Grid.RowDefinitions>
   </Grid>
</Grid>

您应该使用嵌套网格。将一个内部网格放入第1列,并定义一些行:

<Grid Name="outerGrid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid Name="innerGrid" Grid.Column="0">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
    </Grid>
</Grid>

您可以尝试以下布局:

<Grid ShowGridLines="True" >
    <Grid.ColumnDefinitions>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="0">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>                
        </Grid.RowDefinitions>
    </Grid>
</Grid>