How is the property of the parent FrameworkElement set in Silverlight?

I wrote a Controllight-based Silverlight user control. I have two DependencyProperties called Top and Bottom that contain child controls for a specific layout display. Then I use the ControlTemplate to arrange these two controls in the grid, putting them in row 0 and the other in 1 row. The problem is that I cannot figure out how to get each child of the Parent property to point to my user control. When I check each control at runtime, the Parent property of each is null.

This is a simple example, but I think you can see the general problem. I have a few more complex controls that all share this issue. I know that there is some kind of magic that I am missing. If a child device is set for the ContentControl Content property, it somehow sets the parent for itself.

Edit: A little more information

In WPF, you can use functions such as AddVisualChild (), RemoveVisualChild (), AddLogicalChild (), RemoveLogicChild () to manage parent / child relationships, but these functions are not available in Silverlight.

+4
source share
2 answers

After quite a bit of research, I find this impossible. I was able to recursively go through the visual tree instead of the logic tree, using VisualTreeHelper to achieve my final goal.

+4
source

The Parent property cannot be arbitrary; it reflects the real parent element of the control to use when rendering.

From MSDN: A parent can be a Nothing in Visual Basic link in cases where an element was created but not bound to a logical tree that ultimately connects to the root element of the page level or to the application object.

...

As a rule, changing a parent element is carried out only by manipulating collections, using special methods of adding or deleting, or by setting properties of the contents of elements.

+1
source

All Articles