如何通过行和列索引以编程方式访问 WPF Grid 中的控件? [英] How to programmatically access Control in WPF Grid by row and column index?
本文介绍了如何通过行和列索引以编程方式访问 WPF Grid 中的控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一旦控件被添加到 WPF 网格中,有没有办法通过行和/或列索引以编程方式访问它们?大致如下:
Once Controls have been added to a WPF Grid, is there a way to programmatically access them by row and/or column index? Something along the lines of:
var myControl = (object)MyGrid.GetChild(int row, int column);
... GetChild
是我希望拥有的方法!
... where GetChild
is the method I wish I had!
推荐答案
这方面没有内置方法,但您可以通过查看 Children 集合轻松完成:
There isn't a built-in method for this, but you can easily do it by looking in the Children collection:
myGrid.Children
.Cast<UIElement>()
.First(e => Grid.GetRow(e) == row && Grid.GetColumn(e) == column);
这篇关于如何通过行和列索引以编程方式访问 WPF Grid 中的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文