Partilhar via


Como: Desenhar uma Polyline usando o elemento Polyline

This example shows how to draw a polyline, which is a series of connected lines, by using the Polyline element.

To draw a polyline, create a Polyline element and use its Points property to specify the shape vertices. Finally, use the Stroke and StrokeThickness properties to describe the polyline outline because a line without a stroke is invisible.

Observação

Because the Polyline element is not a closed shape, the Fill property has no effect, even if you deliberately close the shape outline.To create a closed shape with a Fill, use a Polygon element.

The following example draws two Polyline elements inside a Canvas.

Exemplo

In Extensible Application Markup Language (XAML), valid syntax for points is a space-delimited list of comma-separated x- and y-coordinate pairs.

<Canvas Height="400" Width="400">


  <Polyline
    Points="10,110 60,10 110,110"
    Stroke="Black"
    StrokeThickness="4" />

  <Polyline
    Points="10,110 110,110 110,10"
    Stroke="Black"
    StrokeThickness="4"
    Canvas.Left="150" />


  </Canvas>

Although this example uses a Canvas to contain the polylines, you can use polyline elements (and all the other shape elements) with any Panel or Control that supports non-text content.

Este exemplo é parte de uma amostra maior; Para obter o exemplo completo, consulte Exemplo de elementos de forma.

Consulte também

Referência

Polyline

Polygon

Shape

Conceitos

Visão geral de Formas e Desenho básico no WPF

Outros recursos

Exemplo de elementos de forma