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.GetDrawing Method

Returns the drawing content of the specified Visual.

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

public static DrawingGroup GetDrawing(
	Visual reference
)

Parameters

reference
Type: System.Windows.Media.Visual

The Visual whose drawing content is returned.

Return Value

Type: System.Windows.Media.DrawingGroup
The drawing content of the Visual returned as a DrawingGroup type.

The following example shows how to retrieve the DrawingGroup from a visual object by using the GetDrawing method. A hit test is then performed on the geometry of each drawing in the DrawingGroup to determine which geometry was hit.

// Determine if a geometry within the visual was hit. 
static public void HitTestGeometryInVisual(Visual visual, Point pt)
{
    // Retrieve the group of drawings for the visual.
    DrawingGroup drawingGroup = VisualTreeHelper.GetDrawing(visual);
    EnumDrawingGroup(drawingGroup, pt);
}

// Enumerate the drawings in the DrawingGroup. 
static public void EnumDrawingGroup(DrawingGroup drawingGroup, Point pt)
{
    DrawingCollection drawingCollection = drawingGroup.Children;

    // Enumerate the drawings in the DrawingCollection. 
    foreach (Drawing drawing in drawingCollection)
    {
        // If the drawing is a DrawingGroup, call the function recursively. 
        if (drawing.GetType() == typeof(DrawingGroup))
        {
            EnumDrawingGroup((DrawingGroup)drawing, pt);
        }
        else if (drawing.GetType() == typeof(GeometryDrawing))
        {
            // Determine whether the hit test point falls within the geometry. 
            if (((GeometryDrawing)drawing).Geometry.FillContains(pt))
            {
                // Perform action based on hit test on geometry.
            }
        }

    }
}

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft