如何访问一个WPF Canvas类的孩子呢? [英] How do you access the children of a WPF Canvas class?
本文介绍了如何访问一个WPF Canvas类的孩子呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何访问一个WPF Canvas类的孩子呢?
How do you access the children of a WPF Canvas class?
这是一个很酷的类,我喜欢你如何能增加孩子。但是,一旦他们在那里,怎么你看他们阅读他们的状态和内容。我知道,如果你把孩子XAML很容易。但是,如果你在运行时动态添加的孩子在画布?
It is a cool class and I like how you are able to add children. But once they are there, how to you look at them for reading their state and content. I know it is easy if you put the children in XAML. But what if you have added children to the canvas dynamically at run time?
推荐答案
您可以使用儿童财产。
编辑:这是迭代的孩子,通过索引获得的一个例子:
Here is an example of iterating over the children and getting one by index:
foreach (UIElement child in canvas.Children)
{
// ...
}
// Or:
int index = 0;
var childByIndex = canvas.Children[index];
这篇关于如何访问一个WPF Canvas类的孩子呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文