本文介绍了如何访问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类的孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 05:37