也可以通过在 XAML 编辑器中键入内容手动向 Grid 中添加行和列。“设计”视图将以新的行和列自动更新。
使用 XAML 编辑器向网格中添加行
在 XAML 编辑器中,找到一个 Grid 元素。
添加一个 Grid.RowDefinitions 元素,将其作为 Grid 元素的子级。代码应类似于:
<Grid>
<Grid.RowDefinitions>
</Grid.RowDefinitions>
</Grid>
添加多个 RowDefinition 元素。下面的标记显示了一个示例:
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="5*" />
</Grid.RowDefinitions>
通过使用 XAML 编辑器向网格中添加列
在 XAML 编辑器中,找到一个 Grid 元素。
添加一个 Grid.ColumnDefinitions 元素,将其作为 Grid 元素的子级。代码应类似于:
<Grid>
<Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
</Grid>
添加多个 ColumnDefinition 元素。下面的标记显示了一个示例:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5*" />
</Grid.ColumnDefinitions>