Compartir a través de


Cómo: Enumerar el contenido de un dibujo de un objeto Visual

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

Ejemplo

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

NotaNota

Al enumerar el contenido del objeto visual, se recuperan objetos Drawing, 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 en WPF.

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

}

 // 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.GetType() == typeof(DrawingGroup))
         {
             EnumDrawingGroup((DrawingGroup)drawing);
         }
         else if (drawing.GetType() == typeof(GeometryDrawing))
         {
             // Perform action based on drawing type.  
         }
         else if (drawing.GetType() == typeof(ImageDrawing))
         {
             // Perform action based on drawing type.
         }
         else if (drawing.GetType() == typeof(GlyphRunDrawing))
         {
             // Perform action based on drawing type.
         }
         else if (drawing.GetType() == typeof(VideoDrawing))
         {
             // Perform action based on drawing type.
         }
     }
 }

Vea también

Referencia

Drawing

DrawingGroup

VisualTreeHelper

Conceptos

Información general sobre objetos Drawing

Información general sobre la representación de gráficos en WPF