How do you access the children of a WPF Canvas class?

How do you access the children of a WPF Canvas class?

This is a cool class and I love the way you can add children. But once they are there, how do you look at them to read their status and content. I know this is easy if you put children in XAML. But what if you added children to the canvas dynamically at runtime?

+3
source share
1 answer

You can use the Children property .


Edit: Here is an example of iterating over child elements and retrieving by index:

foreach (UIElement child in canvas.Children)
{
    // ...
}
// Or: 
int index = 0;
var childByIndex = canvas.Children[index];
+4
source

Source: https://habr.com/ru/post/1752452/


All Articles