Procedura: creare più percorsi secondari in un PathGeometry

In questo esempio viene illustrato come creare più percorsi secondari in un oggetto PathGeometry. Per creare più percorsi secondari, creare un oggetto PathFigure per ogni sottopercorso.

Esempio

Nell'esempio seguente vengono creati due sottopercorso, ognuno dei quali un triangolo.

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

L'esempio seguente illustra come creare più sottopercorso usando una Path sintassi degli attributi XAML e . Ogni M crea un nuovo sottopercorso in modo che l'esempio crei due sottopercorso che ogni disegno di un triangolo.

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

Si noti che questa sintassi di attributo crea effettivamente una StreamGeometryversione più leggera di un oggetto PathGeometry. Per altre informazioni, vedere la pagina Sintassi di markup del percorso.

Vedi anche