【发布时间】:2014-04-15 23:00:17
【问题描述】:
假设您想使用以下代码向 Grid 添加一个新元素:
ExpanderView newExpander = new ExpanderView();
newExpander.Name = name;
newExpander.Header = header;
newExpander.FontSize = 40;
if (row == 0)
newExpander.IsExpanded = true;
foreach (Item li in items)
{
CheckBox tb = new CheckBox();
tb.Content = content;
tb.FontSize = 20;
newExpander.Items.Add(tb);
}
MyGrid.Children.Add(newExpander);
Grid.SetRow(newExpander, row);
现在是 xaml 中的网格:
<Grid x:Name="MyGrid">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
</Grid>
现在是cs代码部分的最后一行Grid.SetRow(newExpander, row),
如果 .xaml 代码中有多个网格,如何告诉它要为哪个网格设置新行?
【问题讨论】:
标签: xaml