#112 – Navigating the Visual Tree in Code

You can use the VisualTreeHelper.GetChildrenCount and GetChild methods to enumerate all objects in a visual tree.

To get all of the children in a visual tree of a specified parent object, you can use a for loop:

            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
                Debug.WriteLine(VisualTreeHelper.GetChild(obj, i));

You could extend this example and descend down the visual tree by calling GetChild methods on the children returned from the first call.

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: