C# wpf如何在网格中的特定行/列中查找画布

C# wpf如何在网格中的特定行/列中查找画布,c#,wpf,C#,Wpf,我将一个网格划分为几行/几列,如何在(x,y)中获得该网格内的画布例如,如何获得第2行第1列内的画布 非常感谢一个“单元格”中可以有多个元素,可能没有很好的方法可以做到这一点,我会使用如下查询: int x = 0; int y = 1; var target = (from UIElement c in grid.Children where Grid.GetRow(c) == y && Grid.GetColumn(c) == x sele

我将一个网格划分为几行/几列,如何在(x,y)中获得该网格内的画布例如,如何获得第2行第1列内的画布


非常感谢

一个“单元格”中可以有多个元素,可能没有很好的方法可以做到这一点,我会使用如下查询:

int x = 0;
int y = 1;
var target = (from UIElement c in grid.Children
         where Grid.GetRow(c) == y && Grid.GetColumn(c) == x
         select c).First();

基于H.B的解决方案,我将在问题的“画布”部分添加一个小测试:

int x = 0;
int y = 1;
var target = (from UIElement c in grid.Children
         where Grid.GetRow(c) == y && Grid.GetColumn(c) == x && c is Canvas
         select c).First();