How to: Create Multiple Subpaths Within a PathGeometry

This example shows how to create multiple subpaths in a PathGeometry. To create multiple subpaths, you create a PathFigure for each subpath.

Example

The following example creates two subpaths, each one a triangle.

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

The following example shows how to create multiple subpaths by using a Path and XAML attribute syntax. Each M creates a new subpath so that the example creates two subpaths that each draw a triangle.

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

(Note that this attribute syntax actually creates a StreamGeometry, a lighter-weight version of a PathGeometry. For more information, see the Path Markup Syntax page.)

See also