DrawingVisual.Drawing Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the drawing content of the DrawingVisual object.
public:
property System::Windows::Media::DrawingGroup ^ Drawing { System::Windows::Media::DrawingGroup ^ get(); };
public System.Windows.Media.DrawingGroup Drawing { get; }
member this.Drawing : System.Windows.Media.DrawingGroup
Public ReadOnly Property Drawing As DrawingGroup
Gets a value of type DrawingGroup that represents the collection of Drawing objects in 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.
}
}
}
' 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.
EnumDrawingGroup(drawingVisual.Drawing)
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
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.
Prodotto | Versioni |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Feedback su .NET
.NET è un progetto di open source. Selezionare un collegamento per fornire feedback: