共用方式為


如何:在 PathGeometry 內建立多個子路徑

此範例示範如何在 中 PathGeometry 建立多個子路徑。 若要建立多個子路徑,您可以為每個子路徑建立 。 PathFigure

範例

下列範例會建立兩個子路徑,每個子路徑各一個三角形。

<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>

下列範例示範如何使用 和 XAML 屬性語法建立多個子路徑 Path 。 每個 M 都會建立新的子路徑,讓範例建立兩個子路徑,每個子路徑都會繪製三角形。

<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 。如需詳細資訊,請參閱 路徑標記語法 頁面。

另請參閱