gpt4 book ai didi

xaml - 将元素添加到网格并设置其行 Windows Phone

转载 作者:行者123 更新时间:2023-12-01 05:02:48 25 4
gpt4 key购买 nike

假设您要使用以下代码向网格添加新元素:

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 代码中有多个网格,您如何告诉它要为哪个网格设置新行?

最佳答案

下面的代码

Grid.SetRow(newExpander, row);

仅当对象属性中的行为 1 时才设置 Grid.Row="1"

要使用此属性,包含对象的网格必须设置 RowDefinitions

How can you tell it which grid you want to set the new row for if you have multiple grids in the .xaml code?

你不需要告诉,因为对象在你添加它的时候仍然在网格中。
当您更改属性 Grid.Row 时,它只会设置在网格的女巫行上,您的控件将被渲染

关于xaml - 将元素添加到网格并设置其行 Windows Phone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23096063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com