如何:在 PathGeometry 内部创建多个子路径

更新:2007 年 11 月

下面的示例演示如何在 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>

下面的示例演示如何使用 Path 和 XAML 属性语法来创建多个子路径。每个 M 都创建一个新的子路径,以便该示例创建两个分别会创建一个三角形的子路径。

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

(请注意,此属性语法实际上会创建一个 StreamGeometryPathGeometry 的轻量版本)。有关更多信息,请参见路径标记语法页。)

请参见

概念

Geometry 概述