此示例演示如何在一个 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" />
(请注意,此属性语法实际上创建了 StreamGeometry,即较轻量版本的 PathGeometry。有关详细信息,请参阅 路径标记语法 页。