HOW TO:列舉 Visual 的繪圖內容
更新:2007 年 11 月
Drawing 物件提供列舉 Visual 內容的物件模型。
範例
下列範例使用 GetDrawing 方法,擷取 Visual 的 DrawingGroup 值並加以列舉。
![]() |
---|
當您列舉視覺內容時,您會擷取 Drawing 物件,而不是擷取轉譯資料的基礎表示做為向量圖形指示清單。如需詳細資訊,請參閱 Windows Presentation Foundation 圖形轉譯概觀。 |
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.
}
}
}
請參閱
概念
Windows Presentation Foundation 圖形轉譯概觀