Skip to main content
VisualTreeHelper Class
 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

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

SystemObject
  System.Windows.MediaVisualTreeHelper

public static class VisualTreeHelper
public ref class VisualTreeHelper abstract sealed 
[<AbstractClass>]
[<Sealed>]
type VisualTreeHelper = class end
Public NotInheritable Class VisualTreeHelper
NameDescription
System_CAPS_pubmethod System_CAPS_static GetBitmapEffect

Returns the BitmapEffect value for the specified Visual.

System_CAPS_pubmethod System_CAPS_static GetBitmapEffectInput

Returns the BitmapEffectInput value for the specified Visual.

System_CAPS_pubmethod System_CAPS_static GetCacheMode

Retrieves the cached representation of the specified Visual.

System_CAPS_pubmethod System_CAPS_static GetChild

Returns the child visual object from the specified collection index within a specified parent.

System_CAPS_pubmethod System_CAPS_static GetChildrenCount

Returns the number of children that the specified visual object contains.

System_CAPS_pubmethod System_CAPS_static GetClip

Return the clip region of the specified Visual as a Geometry value.

System_CAPS_pubmethod System_CAPS_static GetContentBounds

Returns the cached bounding box rectangle for the specified Visual.

System_CAPS_pubmethod System_CAPS_static GetContentBounds

Returns the cached bounding box rectangle for the specified Visual3D.

System_CAPS_pubmethod System_CAPS_static GetDescendantBounds

Returns the union of all the content bounding boxes for all the descendants of the Visual, which includes the content bounding box of the Visual.

System_CAPS_pubmethod System_CAPS_static GetDescendantBounds

Returns the union of all the content bounding boxes for all the descendants of the specified Visual3D, which includes the content bounding box of the Visual3D.

System_CAPS_pubmethod System_CAPS_static GetDpi

Gets the DPI information at which this Visual is measured and rendered.

System_CAPS_pubmethod System_CAPS_static GetDrawing

Returns the drawing content of the specified Visual.

System_CAPS_pubmethod System_CAPS_static GetEdgeMode

Returns the edge mode of the specified Visual as an EdgeMode value.

System_CAPS_pubmethod System_CAPS_static GetEffect

Gets the bitmap effect for the specified Visual.

System_CAPS_pubmethod System_CAPS_static GetOffset

Returns the offset of the Visual.

System_CAPS_pubmethod System_CAPS_static GetOpacity

Returns the opacity of the Visual.

System_CAPS_pubmethod System_CAPS_static GetOpacityMask

Returns a Brush value that represents the opacity mask of the Visual.

System_CAPS_pubmethod System_CAPS_static GetParent

Returns a DependencyObject value that represents the parent of the visual object.

System_CAPS_pubmethod System_CAPS_static GetTransform

Returns a Transform value for the Visual.

System_CAPS_pubmethod System_CAPS_static GetXSnappingGuidelines

Returns an X-coordinate (vertical) guideline collection.

System_CAPS_pubmethod System_CAPS_static GetYSnappingGuidelines

Returns a Y-coordinate (horizontal) guideline collection.

System_CAPS_pubmethod System_CAPS_static HitTest

Initiates a hit test on the specified Visual, with caller-defined HitTestFilterCallback and HitTestResultCallback methods.

System_CAPS_pubmethod System_CAPS_static HitTest

Returns the topmost Visual object of a hit test by specifying a Point.

System_CAPS_pubmethod System_CAPS_static HitTest

Initiates a hit test on the specified Visual3D, with caller-defined HitTestFilterCallback and HitTestResultCallback methods.

System_CAPS_pubmethod System_CAPS_static SetRootDpi

Updates the DPI information of a Visual. It can only be called on a Visual without a parent.

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);
    }
}
' Enumerate all the descendants of the visual object.
Public Shared Sub EnumVisual(ByVal myVisual As Visual)
	For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(myVisual) - 1
		' Retrieve child visual at specified index value.
		Dim childVisual As Visual = CType(VisualTreeHelper.GetChild(myVisual, i), Visual)

		' Do processing of the child visual object.

		' Enumerate children of the child visual object.
		EnumVisual(childVisual)
	Next i
End Sub
.NET Framework
Available since 3.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0

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

Return to top