Language

ジオメトリの概要

この概要では、Windows Presentation Foundation (WPF) Geometry クラスを使用して図形を記述する方法について説明します。 このトピックでは、 Geometry オブジェクトと Shape 要素の違いについても説明します。

ジオメトリとは

Geometry クラスとその派生クラス (EllipseGeometry、PathGeometry、CombinedGeometryなど) を使用すると、2D 図形のジオメトリを記述できます。 これらの幾何学的な説明には、画面に描画する図形の定義やヒット テスト領域とクリップ領域の定義など、多くの用途があります。 ジオメトリを使用してアニメーション パスを定義することもできます。

Geometry オブジェクトは、四角形や円などの単純なものや、2 つ以上のジオメトリ オブジェクトから作成された複合オブジェクトです。 PathGeometryクラスとStreamGeometryクラスを使用すると、より複雑なジオメトリを作成できます。このクラスを使用すると、円弧と曲線を記述できます。

GeometryはFreezableの一種であるため、Geometry オブジェクトには、リソースとして宣言したり、複数のオブジェクト間で共有したり、読み取り専用にしてパフォーマンスを向上したり、複製したり、スレッド セーフにしたりできる、いくつかの特別な機能が用意されています。 Freezable オブジェクトによって提供されるさまざまな機能の詳細については、「Freezable オブジェクトの概要」を参照してください。

ジオメトリと図形

GeometryクラスとShapeクラスは、両方とも 2D 図形を記述する点で似ています (たとえば、EllipseGeometryとEllipseを比較します)。ただし、重要な違いがあります。

1 つの場合、 Geometry クラスは Freezable クラスから継承し、 Shape クラスは FrameworkElementから継承します。 これらは要素であるため、 Shape オブジェクトは自分自身をレンダリングしてレイアウト システムに参加できますが、 Geometry オブジェクトは表示できません。

ShapeオブジェクトはGeometryオブジェクトよりも簡単に使用できますが、Geometryオブジェクトの方が汎用性が高くなります。 Shape オブジェクトは 2D グラフィックスのレンダリングに使用されますが、Geometry オブジェクトを使用して、2D グラフィックスのジオメトリ領域の定義、クリッピングの領域の定義、ヒット テスト用の領域の定義などを行うことができます。

パス図形

1 つの Shape、 Path クラスは、実際には Geometry を使用してその内容を記述します。 Dataを使用してPathのGeometryプロパティを設定し、そのFillプロパティとStrokeプロパティを設定することで、Geometryをレンダリングできます。

ジオメトリを取得する一般的なプロパティ

前のセクションでは、図形の描画、アニメーション化、クリッピングなど、さまざまな目的で Geometry オブジェクトを他のオブジェクトと共に使用できることを説明しました。 次の表に、 Geometry オブジェクトを受け取るプロパティを持ついくつかのクラスを示します。

タイプ プロパティ
DoubleAnimationUsingPath PathGeometry
DrawingGroup ClipGeometry
GeometryDrawing Geometry
Path Data
UIElement Clip

単純なジオメトリの種類

すべてのジオメトリの基底クラスは、抽象クラス Geometryです。 Geometry クラスから派生するクラスは、単純なジオメトリ、パス ジオメトリ、複合ジオメトリの 3 つのカテゴリに大まかにグループ化できます。

単純なジオメトリ クラスには、 LineGeometry、 RectangleGeometry、 EllipseGeometry が含まれており、線、四角形、円などの基本的な幾何学的図形を作成するために使用されます。

  • LineGeometryは、線の始点と終点を指定することによって定義されます。

  • RectangleGeometryは、相対位置と高さと幅を指定するRect構造体で定義されます。 RadiusXプロパティとRadiusYプロパティを設定することで、丸い四角形を作成できます。

  • EllipseGeometryは、中心点、x 半径、および y 半径によって定義されます。 次の例では、レンダリングとクリッピングのための単純なジオメトリを作成する方法を示します。

これらの同じ図形とより複雑な図形は、 PathGeometry を使用するか、ジオメトリ オブジェクトを組み合わせて作成できますが、これらのクラスは、これらの基本的な幾何学的図形を生成するためのより簡単な手段を提供します。

次の例は、LineGeometryを作成してレンダリングする方法を示しています。 前述のように、 Geometry オブジェクトはそれ自体を描画できないため、この例では Path 図形を使用して線をレンダリングします。 線には領域がないため、FillのPath プロパティを設定しても効果はありません。代わりに、StrokeプロパティとStrokeThicknessプロパティのみが指定されます。 次の図は、この例からの出力を示しています。

LineGeometrygraphicsmm_line を する
(10,20) から (100,130) まで描画された LineGeometry

<Path Stroke="Black" StrokeThickness="1" >
  <Path.Data>
    <LineGeometry StartPoint="10,20" EndPoint="100,130" />
  </Path.Data>
</Path>
LineGeometry myLineGeometry = new LineGeometry();
myLineGeometry.StartPoint = new Point(10,20);
myLineGeometry.EndPoint = new Point(100,130);

Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myLineGeometry;
Dim myLineGeometry As New LineGeometry()
myLineGeometry.StartPoint = New Point(10,20)
myLineGeometry.EndPoint = New Point(100,130)

Dim myPath As New Path()
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
myPath.Data = myLineGeometry

次の例では、 EllipseGeometryを作成してレンダリングする方法を示します。 例では、CenterのEllipseGeometryをポイント 50,50に設定し、x 半径と y 半径の両方を 50 に設定し、直径 100 の円を作成します。 楕円の内部は、Path 要素の Fill プロパティに値を割り当てることで塗りつぶされます(この場合は Gold。 次の図は、この例からの出力を示しています。

楕円ジオメトリ
(50,50) の位置に描かれた楕円ジオメトリ

<Path Fill="Gold" Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <EllipseGeometry Center="50,50" RadiusX="50" RadiusY="50" />
  </Path.Data>
</Path>
EllipseGeometry myEllipseGeometry = new EllipseGeometry();
myEllipseGeometry.Center = new Point(50, 50);
myEllipseGeometry.RadiusX = 50;
myEllipseGeometry.RadiusY = 50;

Path myPath = new Path();
myPath.Fill = Brushes.Gold;
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myEllipseGeometry;
Dim myEllipseGeometry As New EllipseGeometry()
myEllipseGeometry.Center = New Point(50, 50)
myEllipseGeometry.RadiusX = 50
myEllipseGeometry.RadiusY = 50

Dim myPath As New Path()
myPath.Fill = Brushes.Gold
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
myPath.Data = myEllipseGeometry

次の例は、RectangleGeometryを作成してレンダリングする方法を示しています。 四角形の位置と寸法は、 Rect 構造体によって定義されます。 位置は 50,50 で、高さと幅の両方が 25され、正方形が作成されます。 次の図は、この例からの出力を示しています。

RectangleGeometry にする
座標50,50に描画された長方形ジオメトリ

<Path Fill="LemonChiffon" Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <RectangleGeometry Rect="50,50,25,25" />
  </Path.Data>
</Path>
RectangleGeometry myRectangleGeometry = new RectangleGeometry();
myRectangleGeometry.Rect = new Rect(50,50,25,25);

Path myPath = new Path();
myPath.Fill = Brushes.LemonChiffon;
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myRectangleGeometry;
Dim myRectangleGeometry As New RectangleGeometry()
myRectangleGeometry.Rect = New Rect(50,50,25,25)

Dim myPath As New Path()
myPath.Fill = Brushes.LemonChiffon
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
myPath.Data = myRectangleGeometry

次の例は、画像のクリップ領域として EllipseGeometry を使用する方法を示しています。 Image オブジェクトは、Width 200、Height 150 で定義されます。 EllipseGeometry値が 100、RadiusX値が 75、RadiusY値が 100,75 のCenterが、イメージのClipプロパティに設定されます。 楕円の領域内にある画像の部分のみが表示されます。 次の図は、この例からの出力を示しています。

graphicsmm_clipexampleクリッピング
画像コントロールをクリップするために使用される EllipseGeometry

<Image
  Source="sampleImages\Waterlilies.jpg"
  Width="200" Height="150" HorizontalAlignment="Left">
  <Image.Clip>
    <EllipseGeometry
      RadiusX="100"
      RadiusY="75"
      Center="100,75"/>
  </Image.Clip>
</Image>

// Create the image to clip.
Image myImage = new Image();
Uri imageUri =
    new Uri(@"C:\\Documents and Settings\\All Users\\Documents\My Pictures\\Sample Pictures\\Water lilies.jpg", UriKind.Relative);
myImage.Source = new BitmapImage(imageUri);
myImage.Width = 200;
myImage.Height = 150;
myImage.HorizontalAlignment = HorizontalAlignment.Left;

// Use an EllipseGeometry to define the clip region.
EllipseGeometry myEllipseGeometry = new EllipseGeometry();
myEllipseGeometry.Center = new Point(100, 75);
myEllipseGeometry.RadiusX = 100;
myEllipseGeometry.RadiusY = 75;
myImage.Clip = myEllipseGeometry;


' Create the image to clip.
Dim myImage As New Image()
Dim imageUri As New Uri("C:\\Documents and Settings\\All Users\\Documents\My Pictures\\Sample Pictures\\Water lilies.jpg", UriKind.Relative)
myImage.Source = New BitmapImage(imageUri)
myImage.Width = 200
myImage.Height = 150
myImage.HorizontalAlignment = HorizontalAlignment.Left

' Use an EllipseGeometry to define the clip region. 
Dim myEllipseGeometry As New EllipseGeometry()
myEllipseGeometry.Center = New Point(100, 75)
myEllipseGeometry.RadiusX = 100
myEllipseGeometry.RadiusY = 75
myImage.Clip = myEllipseGeometry

パス ジオメトリ

PathGeometry クラスとその軽量の同等の StreamGeometry クラスは、円弧、曲線、線で構成される複数の複雑な図形を記述する手段を提供します。

PathGeometryの中心にはPathFigureオブジェクトのコレクションがあるため、各図はPathGeometryの個別の図形を表しているため、名前が付けられます。 各 PathFigure は、それ自体が 1 つ以上の PathSegment オブジェクトで構成され、それぞれが図のセグメントを記述します。

セグメントにはさまざまな種類があります。

セグメントの種類 説明 例
ArcSegment 2 つの点の間に楕円の円弧を作成します。 楕円円弧を作成します。
BezierSegment 2 つの点の間にキュービックベジエ曲線を作成します。 3 次ベジエ曲線を作成します。
LineSegment 2 つの点の間に線を作成します。 PathGeometry で LineSegment を作成する
PolyBezierSegment 一連の三次ベジエ曲線を作成します。 PolyBezierSegment の種類ページを参照してください。
PolyLineSegment 一連のラインを作成します。 PolyLineSegment の種類ページを参照してください。
PolyQuadraticBezierSegment 一連の 2 次ベジエ曲線を作成します。 PolyQuadraticBezierSegmentページを参照してください。
QuadraticBezierSegment 2 次ベジエ曲線を作成します。 二次ベジエ曲線を作成します。

PathFigure内のセグメントは 1 つの幾何学的図形に結合され、各セグメントの終点が次のセグメントの始点になります。 StartPointのPathFigure プロパティは、最初のセグメントの描画元のポイントを指定します。 後続の各セグメントは、前のセグメントの終点から開始します。 たとえば、10,50から10,150までの垂直線を定義するには、StartPoint プロパティを10,50に設定し、LineSegmentのPointプロパティ設定を使用して10,150を作成します。

次の例では、PathGeometryを持つ単一のPathFigureで構成される単純なLineSegmentを作成し、Path要素を使用して表示します。 PathFigure オブジェクトのStartPointは10,20に設定され、LineSegmentは100,130の終点で定義されます。 次の図は、この例で作成された PathGeometry を示しています。

LineGeometrygraphicsmm_line を する
1 つのラインセグメントを含むパスジオメトリ

<Path Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>
        <PathFigure StartPoint="10,20">
          <PathFigure.Segments>
            <LineSegment Point="100,130"/>
          </PathFigure.Segments>
        </PathFigure>
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>

// Create a figure that describes a
// line from (10,20) to (100,130).
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new Point(10,20);
myPathFigure.Segments.Add(
    new LineSegment(new Point(100,130),
    true /* IsStroked */ ));

/// Create a PathGeometry to contain the figure.
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures.Add(myPathFigure);

// Display the PathGeometry.
Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;

' Create a figure that describes a 
' line from (10,20) to (100,130).
Dim myPathFigure As New PathFigure()
myPathFigure.StartPoint = New Point(10,20)
myPathFigure.Segments.Add(New LineSegment(New Point(100,130), True)) ' IsStroked 

''' Create a PathGeometry to contain the figure.
Dim myPathGeometry As New PathGeometry()
myPathGeometry.Figures.Add(myPathFigure)

' Display the PathGeometry. 
Dim myPath As New Path()
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
myPath.Data = myPathGeometry

この例と前の LineGeometry 例を比較する価値があります。 PathGeometryに使用される構文は、単純なLineGeometryで使用される構文よりもはるかに詳細であり、この場合はLineGeometry クラスを使用する方が理にかなっているかもしれませんが、PathGeometryの詳細な構文を使用すると、非常に複雑で複雑な幾何学的領域が可能になります。

PathSegment オブジェクトの組み合わせを使用して、より複雑なジオメトリを作成できます。

次の例では、 BezierSegment、 LineSegment、および ArcSegment を使用して図形を作成します。 最初に 3 次ベジエ曲線を作成する例は、始点(前のセグメントの終点)、終点(Point3)、2 つの制御点(Point1 と Point2)の 4 つの点を定義します。 3次ベジエ曲線の2つの制御点は磁石のように作用し、それによって直線の一部を自分自身に引き寄せ、曲線を形成します。 第 1 の制御点 Point1、曲線の開始部分に影響します。2 番目の制御点 Point2は、曲線の終了部分に影響します。

次に、LineSegment を追加します。これは、前の BezierSegment の終点から、その LineSegment プロパティで指定されたポイントまで描画されます。

次に、ArcSegment を追加します。これは、前のLineSegmentの終点からPointプロパティで指定されたポイントに描画されます。 この例では、円弧の x 半径と y 半径 (Size)、回転角度 (RotationAngle)、結果の円弧の角度の大きさを示すフラグ (IsLargeArc)、円弧の描画方向を示す値 (SweepDirection) も指定します。 次の図は、この例で作成された図形を示しています。

円弧を持つ PathGeometry。
パスジオメトリ (PathGeometry)

<Path Stroke="Black" StrokeThickness="1" >
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>
        <PathFigure StartPoint="10,50">
          <PathFigure.Segments>
            <BezierSegment
              Point1="100,0"
              Point2="200,200"
              Point3="300,100"/>
            <LineSegment Point="400,100" />
            <ArcSegment
              Size="50,50" RotationAngle="45"
              IsLargeArc="True" SweepDirection="Clockwise"
              Point="200,100"/>
          </PathFigure.Segments>
        </PathFigure>
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>

// Create a figure.
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new Point(10,50);
myPathFigure.Segments.Add(
    new BezierSegment(
        new Point(100,0),
        new Point(200,200),
        new Point(300,100),
        true /* IsStroked */  ));
myPathFigure.Segments.Add(
    new LineSegment(
        new Point(400,100),
        true /* IsStroked */ ));
myPathFigure.Segments.Add(
    new ArcSegment(
        new Point(200,100),
        new Size(50,50),
        45,
        true, /* IsLargeArc */
        SweepDirection.Clockwise,
        true /* IsStroked */ ));

/// Create a PathGeometry to contain the figure.
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures.Add(myPathFigure);

// Display the PathGeometry.
Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;

' Create a figure.
Dim myPathFigure As New PathFigure()
myPathFigure.StartPoint = New Point(10,50)
myPathFigure.Segments.Add(New BezierSegment(New Point(100,0), New Point(200,200), New Point(300,100), True)) ' IsStroked 
myPathFigure.Segments.Add(New LineSegment(New Point(400,100), True)) ' IsStroked 
myPathFigure.Segments.Add(New ArcSegment(New Point(200,100), New Size(50,50), 45, True, SweepDirection.Clockwise, True)) ' IsStroked  -  IsLargeArc 

''' Create a PathGeometry to contain the figure.
Dim myPathGeometry As New PathGeometry()
myPathGeometry.Figures.Add(myPathFigure)

' Display the PathGeometry. 
Dim myPath As New Path()
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
myPath.Data = myPathGeometry

さらに複雑なジオメトリは、PathFigure内の複数のPathGeometry オブジェクトを使用して作成できます。

次の例では、2 つのPathGeometry オブジェクトを含むPathFigureを作成します。それぞれに複数のPathSegment オブジェクトが含まれています。 上記の例のPathFigureと、PathFigureとPolyLineSegmentを含むQuadraticBezierSegmentが使用されます。 PolyLineSegmentはポイントの配列で定義され、QuadraticBezierSegmentは制御ポイントと終点で定義されます。 次の図は、この例で作成された図形を示しています。

2 つの PathFigure オブジェクトを含む円弧を持つ PathGeometry。
複数の図形を含む PathGeometry

<Path Stroke="Black" StrokeThickness="1" >
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>
        <PathFigure StartPoint="10,50">
          <PathFigure.Segments>
            <BezierSegment
              Point1="100,0"
              Point2="200,200"
              Point3="300,100"/>
            <LineSegment Point="400,100" />
            <ArcSegment
              Size="50,50" RotationAngle="45"
              IsLargeArc="True" SweepDirection="Clockwise"
              Point="200,100"/>
          </PathFigure.Segments>
        </PathFigure>
        
        <PathFigure StartPoint="10,100">
          <PathFigure.Segments>
            <PolyLineSegment Points="50,100 50,150" />
            <QuadraticBezierSegment Point1="200,200" Point2="300,100"/>
          </PathFigure.Segments>
        </PathFigure>                
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>

PathGeometry myPathGeometry = new PathGeometry();

// Create a figure.
PathFigure pathFigure1 = new PathFigure();
pathFigure1.StartPoint = new Point(10,50);
pathFigure1.Segments.Add(
    new BezierSegment(
        new Point(100,0),
        new Point(200,200),
        new Point(300,100),
        true /* IsStroked */ ));
pathFigure1.Segments.Add(
    new LineSegment(
        new Point(400,100),
        true /* IsStroked */ ));
pathFigure1.Segments.Add(
    new ArcSegment(
        new Point(200,100),
        new Size(50,50),
        45,
        true, /* IsLargeArc */
        SweepDirection.Clockwise,
        true /* IsStroked */ ));
myPathGeometry.Figures.Add(pathFigure1);

// Create another figure.
PathFigure pathFigure2 = new PathFigure();
pathFigure2.StartPoint = new Point(10,100);
Point[] polyLinePointArray =
    new Point[]{ new Point(50, 100), new Point(50, 150)};
PolyLineSegment myPolyLineSegment = new PolyLineSegment();
myPolyLineSegment.Points =
    new PointCollection(polyLinePointArray);
pathFigure2.Segments.Add(myPolyLineSegment);
pathFigure2.Segments.Add(
    new QuadraticBezierSegment(
        new Point(200,200),
        new Point(300,100),
        true /* IsStroked */ ));
myPathGeometry.Figures.Add(pathFigure2);

// Display the PathGeometry.
Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;

Dim myPathGeometry As New PathGeometry()

' Create a figure.
Dim pathFigure1 As New PathFigure()
pathFigure1.StartPoint = New Point(10,50)
pathFigure1.Segments.Add(New BezierSegment(New Point(100,0), New Point(200,200), New Point(300,100), True)) ' IsStroked 
pathFigure1.Segments.Add(New LineSegment(New Point(400,100), True)) ' IsStroked 
pathFigure1.Segments.Add(New ArcSegment(New Point(200,100), New Size(50,50), 45, True, SweepDirection.Clockwise, True)) ' IsStroked  -  IsLargeArc 
myPathGeometry.Figures.Add(pathFigure1)

' Create another figure.
Dim pathFigure2 As New PathFigure()
pathFigure2.StartPoint = New Point(10,100)
Dim polyLinePointArray() As Point = { New Point(50, 100), New Point(50, 150)}
Dim myPolyLineSegment As New PolyLineSegment()
myPolyLineSegment.Points = New PointCollection(polyLinePointArray)
pathFigure2.Segments.Add(myPolyLineSegment)
pathFigure2.Segments.Add(New QuadraticBezierSegment(New Point(200,200), New Point(300,100), True)) ' IsStroked 
myPathGeometry.Figures.Add(pathFigure2)

' Display the PathGeometry. 
Dim myPath As New Path()
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
myPath.Data = myPathGeometry

StreamGeometry

PathGeometry クラスと同様に、StreamGeometryは、曲線、円弧、および線を含む複雑な幾何学的形状を定義します。 PathGeometryとは異なり、StreamGeometryの内容は、データ バインディング、アニメーション、または変更をサポートしていません。 複雑なジオメトリを記述する必要があるが、データ バインディング、アニメーション、または変更をサポートするオーバーヘッドが不要な場合は、StreamGeometry を使用します。 効率のため、 StreamGeometry クラスは装飾を記述するための適切な選択肢です。

例については、「 StreamGeometry を使用して図形を作成する」を参照してください。

パス マークアップ構文

PathGeometry型とStreamGeometry型では、特殊な一連の移動および描画コマンドを使用して、拡張アプリケーション マークアップ言語 (XAML) 属性構文がサポートされます。 詳細については、「 パス マークアップ構文」を参照してください。

複合ジオメトリ

複合ジオメトリ オブジェクトは、 GeometryGroup、 CombinedGeometry、または静的 Geometry メソッド Combineを呼び出すことによって作成できます。

  • CombinedGeometry オブジェクトと Combine メソッドは、ブール演算を実行して、2 つのジオメトリで定義された領域を結合します。 Geometry 領域のないオブジェクトは破棄されます。 結合できる Geometry オブジェクトは 2 つだけです (ただし、これら 2 つのジオメトリは複合ジオメトリである場合もあります)。

  • GeometryGroup クラスは、その領域を組み合わせずに、含まれるGeometry オブジェクトの結合を作成します。 Geometryには、任意の数のGeometryGroup オブジェクトを追加できます。 例については、「 複合図形を作成する」を参照してください。

結合操作は実行されないため、 GeometryGroup オブジェクトを使用すると、 CombinedGeometry オブジェクトまたは Combine メソッドを使用するよりもパフォーマンス上の利点があります。

結合されたジオメトリ

前のセクションでは、 CombinedGeometry オブジェクトと Combine メソッドを使用して、含まれるジオメトリによって定義された領域を結合しました。 GeometryCombineMode列挙体は、ジオメトリの結合方法を指定します。 GeometryCombineMode プロパティに指定できる値は、Union、Intersect、Exclude、およびXorです。

次の例では、 CombinedGeometry は結合モードの Union で定義されています。 Geometry1 と Geometry2 はどちらも同じ半径の円として定義されますが、中心のオフセットは 50 です。

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>
    
    <!-- Combines two geometries using the union combine mode. -->
    <CombinedGeometry GeometryCombineMode="Union">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>

Union 結合モードの結果

次の例では、 CombinedGeometry は Xorの結合モードで定義されています。 Geometry1 と Geometry2 はどちらも同じ半径の円として定義されますが、中心のオフセットは 50 です。

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>
    
    <!-- Combines two geometries using the XOR combine mode. -->
    <CombinedGeometry GeometryCombineMode="Xor">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>

Xor 結合モードの結果 の結果

その他の例については、「 複合図形を作成する 」および「 結合ジオメトリを作成する」を参照してください。

Freezable 機能

Freezable クラスから継承されるため、Geometry クラスにはいくつかの特別な機能が用意されています。Geometry オブジェクトは XAML リソースとして宣言でき、複数のオブジェクト間で共有され、読み取り専用にしてパフォーマンスを向上させ、複製し、スレッド セーフにすることができます。 Freezable オブジェクトによって提供されるさまざまな機能の詳細については、「Freezable オブジェクトの概要」を参照してください。

その他のジオメトリフィーチャ

Geometry クラスには、次のような便利なユーティリティ メソッドも用意されています。

メソッドの完全な一覧については、 Geometry クラスを参照してください。

こちらも参照ください