WPF has a “VisualTreeHelper” class that provides the functionality to retrieve the parent objects of a visual object using the GetParent() method and child objects of a visual object using the GetChild() method by specifying the index value of the child.
The following code snippet is used to enumerate all the child objects of a visual object.
[C#]
public void ChildEnum(Visual Visualobj)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(Visualobj); i++)
{
Visual childVisual = (Visual)VisualTreeHelper.GetChild(Visualobj, i);
VisualEnum(childVisual);
}
}
Share with