Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

VisualTreeHelper Class

Updated: July 2008

Provides utility methods that perform common tasks involving nodes in a visual tree.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

public static class VisualTreeHelper
You cannot directly create an instance of this class in XAML.

Nodes in the visual tree can be either Visual or Visual3D objects. Methods that are specific to a type of visual object are typed as either Visual or Visual3D. However, some methods in the VisualTreeHelper class can accept a DependencyObject value that represents either type of visual object.

WPF supports programmatic access to several different tree structures of objects. Primarily, this is exposed as a visual tree and a logical tree. In some cases, the logical tree is a more useful representation of the elements in a WPF application, but conceptually the logical tree is implemented at a level beyond the Visual class. Unlike the visual tree, the logical tree can represent nonvisual data objects, such as ListItem. For more information on the logical tree, see Trees in WPF. The logical tree also is supported by a similar utility method class, LogicalTreeHelper.

The following example shows how to enumerate all the descendants of a visual object, which is a technique you might want to use if you were interested in serializing all the rendering information of a visual object hierarchy.

// Enumerate all the descendants of the visual object. 
static public void EnumVisual(Visual myVisual)
{
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
    {
        // Retrieve child visual at specified index value.
        Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);

        // Do processing of the child visual object. 

        // Enumerate children of the child visual object.
        EnumVisual(childVisual);
    }
}

System.Object
  System.Windows.Media.VisualTreeHelper

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Date

History

Reason

July 2008

Added new member: GetEffect method.

SP1 feature change.

Community Additions

Show:
© 2014 Microsoft