Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

VisualTreeHelper Class

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

System.Object
  System.Windows.Media.VisualTreeHelper

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
public static class VisualTreeHelper

The VisualTreeHelper type exposes the following members.

  NameDescription
Public methodStatic memberGetBitmapEffectReturns the BitmapEffect value for the specified Visual.
Public methodStatic memberGetBitmapEffectInputReturns the BitmapEffectInput value for the specified Visual.
Public methodStatic memberGetCacheModeRetrieves the cached representation of the specified Visual.
Public methodStatic memberGetChildReturns the child visual object from the specified collection index within a specified parent.
Public methodStatic memberGetChildrenCountReturns the number of children that the specified visual object contains.
Public methodStatic memberGetClipReturn the clip region of the specified Visual as a Geometry value.
Public methodStatic memberGetContentBounds(Visual)Returns the cached bounding box rectangle for the specified Visual.
Public methodStatic memberGetContentBounds(Visual3D)Returns the cached bounding box rectangle for the specified Visual3D.
Public methodStatic memberGetDescendantBounds(Visual)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.
Public methodStatic memberGetDescendantBounds(Visual3D)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.
Public methodStatic memberGetDrawingReturns the drawing content of the specified Visual.
Public methodStatic memberGetEdgeModeReturns the edge mode of the specified Visual as an EdgeMode value.
Public methodStatic memberGetEffectGets the bitmap effect for the specified Visual.
Public methodStatic memberGetOffsetReturns the offset of the Visual.
Public methodStatic memberGetOpacityReturns the opacity of the Visual.
Public methodStatic memberGetOpacityMaskReturns a Brush value that represents the opacity mask of the Visual.
Public methodStatic memberGetParentReturns a DependencyObject value that represents the parent of the visual object.
Public methodStatic memberGetTransformReturns a Transform value for the Visual.
Public methodStatic memberGetXSnappingGuidelinesReturns an X-coordinate (vertical) guideline collection.
Public methodStatic memberGetYSnappingGuidelinesReturns a Y-coordinate (horizontal) guideline collection.
Public methodStatic memberHitTest(Visual, Point)Returns the topmost Visual object of a hit test by specifying a Point.
Public methodStatic memberHitTest(Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters)Initiates a hit test on the specified Visual, with caller-defined HitTestFilterCallback and HitTestResultCallback methods.
Public methodStatic memberHitTest(Visual3D, HitTestFilterCallback, HitTestResultCallback, HitTestParameters3D)Initiates a hit test on the specified Visual3D, with caller-defined HitTestFilterCallback and HitTestResultCallback methods.
Top

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);
    }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft. All rights reserved.