Compartir a través de


Cómo enumerar el contenido de dibujo de un visual

El Drawing objeto proporciona un modelo de objetos para enumerar el contenido de .Visual

Ejemplo

En el siguiente ejemplo se usa el método GetDrawing para recuperar el valor DrawingGroup de un Visual y enumerarlo.

Nota:

Al enumerar el contenido del objeto visual, está recuperando Drawing objetos y no la representación subyacente de los datos de representación como una lista de instrucciones de gráficos vectoriales. Para obtener más información, vea Información general sobre la representación de gráficos de WPF.

public void RetrieveDrawing(Visual v)
{
    DrawingGroup drawingGroup = VisualTreeHelper.GetDrawing(v);
    EnumDrawingGroup(drawingGroup);
}

// Enumerate the drawings in the DrawingGroup.
public void EnumDrawingGroup(DrawingGroup drawingGroup)
{
    DrawingCollection dc = drawingGroup.Children;

    // Enumerate the drawings in the DrawingCollection.
    foreach (Drawing drawing in dc)
    {
        // If the drawing is a DrawingGroup, call the function recursively.
        if (drawing is DrawingGroup group)
        {
            EnumDrawingGroup(group);
        }
        else if (drawing is GeometryDrawing)
        {
            // Perform action based on drawing type.
        }
        else if (drawing is ImageDrawing)
        {
            // Perform action based on drawing type.
        }
        else if (drawing is GlyphRunDrawing)
        {
            // Perform action based on drawing type.
        }
        else if (drawing is VideoDrawing)
        {
            // Perform action based on drawing type.
        }
    }
}

Consulte también