Reputation: 9479
How do you access the children of a WPF Canvas class?
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?
Upvotes: 3
Views: 14679
Reputation: 59129
You can use the Children property.
Edit: 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];
Upvotes: 4