Question

Is it possible to add a parent to the UIElement in C#? I know it's possible to do it with children like this:

(AssociatedObject as Grid).Children.Add(imageObject);

I can't find any way to set the parent of a UIElement, and can't find very much on Google either.

Was it helpful?

Solution

No, it's not. The UIElement class actually doesn't support adding a Parent or Children.

Your example uses the Grid class (which does, in fact, allow you to add children). You'd have to add the child element to the parent element using the parent's children collection (assuming the parent is of a type that allows adding children).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top