Compartilhar via


Como criar uma forma usando um PathGeometry

Este exemplo mostra como criar uma forma usando a PathGeometry classe. PathGeometry Os objetos são compostos por um ou mais PathFigure objetos, cada PathFigure um representando uma "figura" ou forma diferente. Cada PathFigure um é composto por um ou mais PathSegment objetos, cada um representando uma porção conectada da figura ou forma. Os tipos de segmento incluem LineSegment, ArcSegmente BezierSegment.

Exemplo

O exemplo a seguir usa um para criar um PathGeometry triângulo. O PathGeometry é exibido usando um Path elemento .

<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>
        </PathFigureCollection>
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>

A ilustração a seguir mostra a forma criada no exemplo anterior.

A PathGeometry
Um triângulo criado com um PathGeometry

O exemplo anterior mostrou como criar uma forma relativamente simples: um triângulo. A PathGeometry também pode ser usado para criar formas mais complexas, incluindo arcos e curvas. Para obter exemplos, veja Criar um arco elíptico, Criar uma curva de Bézier cúbica e Criar uma curva de Bézier quadrática.

Este exemplo faz parte de um exemplo maior; para ver o exemplo completo, confira o Exemplo de geometrias.

Confira também