I need to get the content of cell in a Grid
in C#. Is there a way to do something like this?
我需要在C#中获取Grid中的单元格内容。有没有办法做这样的事情?
UIElement element = MyGrid.Children.getElementAt(x, y)
1 个解决方案
#1
11
You could use Linq:
你可以使用Linq:
// using System.Linq;
var element = grid.Children.Cast<UIElement>().
FirstOrDefault(e => Grid.GetColumn(e) == x && Grid.GetRow(e) == y);
or if there is more than one element in the specified cell:
或者如果指定的单元格中有多个元素:
var elements = grid.Children.Cast<UIElement>().
Where(e => Grid.GetColumn(e) == x && Grid.GetRow(e) == y);
where elements is an IEnumerable<UIElement>
.
其中elements是IEnumerable
#1
11
You could use Linq:
你可以使用Linq:
// using System.Linq;
var element = grid.Children.Cast<UIElement>().
FirstOrDefault(e => Grid.GetColumn(e) == x && Grid.GetRow(e) == y);
or if there is more than one element in the specified cell:
或者如果指定的单元格中有多个元素:
var elements = grid.Children.Cast<UIElement>().
Where(e => Grid.GetColumn(e) == x && Grid.GetRow(e) == y);
where elements is an IEnumerable<UIElement>
.
其中elements是IEnumerable