DrawingVisual.Drawing Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the drawing content of the DrawingVisual object.

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

Public ReadOnly Property Drawing As DrawingGroup

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 WPF 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 Sub RetrieveDrawings(ByVal visualHost As Visual)
	For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(visualHost) - 1
		' Retrieve child visual at specified index value.
		Dim dependencyObject As DependencyObject = VisualTreeHelper.GetChild(visualHost, i)

		' Determine if the child object is a DrawingVisual.
		If dependencyObject.GetType() Is GetType(DrawingVisual) Then
			Dim drawingVisual As DrawingVisual = CType(dependencyObject, DrawingVisual)

			If drawingVisual.Drawing IsNot Nothing Then
				If drawingVisual.Drawing.GetType() Is GetType(DrawingGroup) Then
					' Enumerate the drawings in the DrawingGroup.
				End If
			End If
		End If
	Next i
End Sub

 ' Enumerate the drawings in the DrawingGroup.
 Public Sub EnumDrawingGroup(ByVal drawingGroup As DrawingGroup)
	 Dim dc As DrawingCollection = drawingGroup.Children

	 ' Enumerate the drawings in the DrawingCollection.
	 For Each drawing As Drawing In dc
		 ' If the drawing is a DrawingGroup, call the function recursively.
		 If drawing.GetType() Is GetType(DrawingGroup) Then
			 EnumDrawingGroup(CType(drawing, DrawingGroup))
		 End If

		 If drawing.GetType() Is GetType(GeometryDrawing) Then
			 ' Perform action based on drawing type.
		 End If
	 Next drawing
 End Sub

.NET Framework
Available since 3.0
Return to top