VisualTreeHelper.GetDrawing(Visual) VisualTreeHelper.GetDrawing(Visual) VisualTreeHelper.GetDrawing(Visual) VisualTreeHelper.GetDrawing(Visual) Method

Definición

Devuelve el contenido de dibujo del objeto Visual especificado.Returns the drawing content of the specified Visual.

public:
 static System::Windows::Media::DrawingGroup ^ GetDrawing(System::Windows::Media::Visual ^ reference);
public static System.Windows.Media.DrawingGroup GetDrawing (System.Windows.Media.Visual reference);
static member GetDrawing : System.Windows.Media.Visual -> System.Windows.Media.DrawingGroup
Public Shared Function GetDrawing (reference As Visual) As DrawingGroup

Parámetros

reference
Visual Visual Visual Visual

Objeto Visual cuyo contenido de dibujo se devuelve.The Visual whose drawing content is returned.

Devoluciones

Contenido de dibujo del objeto Visual que se devuelve como un tipo de DrawingGroup.The drawing content of the Visual returned as a DrawingGroup type.

Ejemplos

El ejemplo siguiente muestra cómo recuperar el DrawingGroup desde un objeto visual mediante el uso de la GetDrawing método.The following example shows how to retrieve the DrawingGroup from a visual object by using the GetDrawing method. A continuación, se realiza una prueba de posicionamiento en la geometría de cada dibujo de la DrawingGroup para determinar qué geometría se posicionó.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.
            }
        }

    }
}
' Determine if a geometry within the visual was hit.
Public Shared Sub HitTestGeometryInVisual(ByVal visual As Visual, ByVal pt As Point)
	' Retrieve the group of drawings for the visual.
	Dim drawingGroup As DrawingGroup = VisualTreeHelper.GetDrawing(visual)
	EnumDrawingGroup(drawingGroup, pt)
End Sub

' Enumerate the drawings in the DrawingGroup.
Public Shared Sub EnumDrawingGroup(ByVal drawingGroup As DrawingGroup, ByVal pt As Point)
	Dim drawingCollection As DrawingCollection = drawingGroup.Children

	' Enumerate the drawings in the DrawingCollection.
	For Each drawing As Drawing In drawingCollection
		' If the drawing is a DrawingGroup, call the function recursively.
		If drawing.GetType() Is GetType(DrawingGroup) Then
			EnumDrawingGroup(CType(drawing, DrawingGroup), pt)
		ElseIf drawing.GetType() Is GetType(GeometryDrawing) Then
			' Determine whether the hit test point falls within the geometry.
			If (CType(drawing, GeometryDrawing)).Geometry.FillContains(pt) Then
				' Perform action based on hit test on geometry.
			End If
		End If

	Next drawing
End Sub

Se aplica a