DrawingVisual.Drawing 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取对象的 DrawingVisual 绘图内容。
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
属性值
获取一个类型的 DrawingGroup 值,该值表示 Drawing 对象集合中的 DrawingVisual对象 。
示例
在以下示例中, DrawingGroup 枚举主机视觉对象中的每个值 DrawingVisual 。
// 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
注解
视觉对象将其呈现数据存储为矢量图形指令列表。 指令列表中的每个项都表示采用序列化格式的低级别图形数据集。 有关视觉对象如何存储图形数据的详细信息,请参阅 WPF 图形呈现概述。
返回值的任何更改都不会由 DrawingVisual.DrawingGroup