我今天已经问过这个问题,为什么我在这段代码中得到一个异常(在这里查看)。现在我不再收到异常,但它返回的标签为空(它不返回标签)。如有进一步问题,请随时提问。
如果我调试代码并打开 grid.children 我得到以下路径:
grid.children --> not open members (in German it says: "nicht öffentliche member") --> _visualChildren --> not open members --> _items --> _my label i want to get_
我的代码:
for (int i = 0; i < numberOfBooks; i++)
{
Grid grid = new Grid();
RowDefinition row = new RowDefinition();
ColumnDefinition column = new ColumnDefinition();
ColumnDefinition column2 = new ColumnDefinition();
ColumnDefinition column3 = new ColumnDefinition();
Label label = new Label();
label.Content = Books[i].Titel;
downGrid.RowDefinitions.Add(row);
grid.ColumnDefinitions.Add(column);
grid.ColumnDefinitions.Add(column2);
grid.ColumnDefinitions.Add(column3);
Grid.SetRow(label, i);
Grid.SetColumn(label, 0);
Grid.SetRow(grid, i);
upperGrid.Children.Add(grid);
grid.Children.Add(label);
grid.MouseLeftButtonDown += (sen, evg) =>
{
Label lbl = grid.Children.OfType<Label>().FirstOrDefault(k => .Name=="label");
string result = lbl?.Name;
Console.WriteLine(result);
};
}
慕标5832272
相关分类