次の方法で共有


方法 : ビジュアルの描画コンテンツを列挙する

更新 : 2007 年 11 月

Drawing オブジェクトは、Visual のコンテンツを列挙するためのオブジェクト モデルを提供します。

使用例

GetDrawing メソッドを使用して VisualDrawingGroup 値を取得し、列挙する例を次に示します。

Aa969822.alert_note(ja-jp,VS.90).gifメモ :

ビジュアルのコンテンツを列挙すると、ベクタ グラフィックス命令リストとして基になるレンダリング データ表現が取得されるのではなく、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.
         }
     }
 }

参照

概念

Drawing オブジェクトの概要

Windows Presentation Foundation のグラフィックス レンダリングの概要

参照

Drawing

DrawingGroup

VisualTreeHelper