1 out of 1 rated this helpful - Rate this topic

DrawingVisual.Drawing Property

Gets the drawing content of the DrawingVisual object.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
public DrawingGroup Drawing { get; }
You cannot set this property in XAML.

Property Value

Type: System.Windows.Media.DrawingGroup
Gets a value of type DrawingGroup that represents the collection of Drawing objects in the DrawingVisual.

A visual object stores its rendering data as a vector graphics instruction list. Each item in the instruction list represents a low-level set of graphics data in a serialized format. For more information on how visual objects store graphics data, see Windows Presentation Foundation Graphics Rendering Overview.

Any change to the returned DrawingGroup value is not persisted by the DrawingVisual.

In the following example, the DrawingGroup value of each DrawingVisual in a host visual is enumerated.

// Enumerate the DrawingVisual children of a host visual. 
public void RetrieveDrawings(Visual visualHost)
{
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visualHost); i++)
    {
        // Retrieve child visual at specified index value.
        DependencyObject dependencyObject = VisualTreeHelper.GetChild(visualHost, i);

        // Determine if the child object is a DrawingVisual. 
        if (dependencyObject.GetType() == typeof(DrawingVisual))
        {
            DrawingVisual drawingVisual = (DrawingVisual)dependencyObject;

            if (drawingVisual.Drawing != null)
            {
                if (drawingVisual.Drawing.GetType() == typeof(DrawingGroup))
                {
                    // Enumerate the drawings in the DrawingGroup.
                    EnumDrawingGroup(drawingVisual.Drawing);
                }
            }
        }
     }
 }

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

         if (drawing.GetType() == typeof(GeometryDrawing))
         {
             // Perform action based on drawing type.
         }
     }
 }

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.