次の方法で共有


方法: PathGeometry 内に複数のサブパスを作成する

この例では、PathGeometryで複数のサブパスを作成する方法を示します。 複数のサブパスを作成するには、サブパスごとに PathFigure を作成します。

次の例では、2 つのサブパス (それぞれ三角形) を作成します。

<Path Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>
        <PathFigureCollection>
          <PathFigure IsClosed="True" StartPoint="10,100">
            <PathFigure.Segments>
              <PathSegmentCollection>
                <LineSegment Point="100,100" />
                <LineSegment Point="100,50" />
              </PathSegmentCollection>
            </PathFigure.Segments>
          </PathFigure>
          <PathFigure IsClosed="True" StartPoint="10,10">
            <PathFigure.Segments>
              <PathSegmentCollection>
                <LineSegment Point="100,10" />
                <LineSegment Point="100,40" />
              </PathSegmentCollection>
            </PathFigure.Segments>
          </PathFigure>                    
        </PathFigureCollection>
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>

次の例は、Path および XAML 属性構文を使用して複数のサブパスを作成する方法を示しています。 各 M は新しいサブパスを作成し、この例では、それぞれが三角形を描画する 2 つのサブパスを作成します。

<Path Stroke="Black" StrokeThickness="1" 
  Data="M 10,100 L 100,100 100,50 Z M 10,10 100,10 100,40 Z" />

(この属性構文は、実際には StreamGeometryの軽量バージョンである PathGeometryを作成します。詳細については、「パス マークアップ構文 ページ」を参照してください。

こちらも参照ください