代码之家  ›  专栏  ›  技术社区  ›  Yanshof

如何在运行时从grid.row获取控件?

wpf
  •  0
  • Yanshof  · 技术社区  · 14 年前

    我有一个 Grid 用3 Rectangle 在里面。我需要一个矩形的引用 Grid.Row == 3 在运行时。

    我怎样才能接触到它?

    谢谢

    1 回复  |  直到 14 年前
        1
  •  5
  •   Jon    14 年前
    var target = myGrid.Children
                 .Cast<UIElement>() // make it into IEnumerable<UIElement>
                 .OfType<Rectangle>() // and select only Rectangles
                 .Where(c => Grid.GetRow(c) == 3);
    

    Rectangle Grid.Row target.Single() target.First()