Compartilhar via


Como criar uma linha usando um LineGeometry

Este exemplo mostra como usar a LineGeometry classe para descrever uma linha. A LineGeometry é definido por seus pontos de início e fim.

Exemplo

O exemplo a seguir mostra como criar e renderizar um LineGeometryarquivo . Um Path elemento é usado para renderizar a linha. Como uma linha não tem área, a Path do objeto Fill não é especificada, em vez disso, as Stroke propriedades e StrokeThickness são usadas.

<Path Stroke="Black" StrokeThickness="1" >
  <Path.Data>
    <LineGeometry StartPoint="10,20" EndPoint="100,130" />
  </Path.Data>
</Path>
LineGeometry myLineGeometry = new LineGeometry();
myLineGeometry.StartPoint = new Point(10,20);
myLineGeometry.EndPoint = new Point(100,130);

Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myLineGeometry;
Dim myLineGeometry As New LineGeometry()
myLineGeometry.StartPoint = New Point(10,20)
myLineGeometry.EndPoint = New Point(100,130)

Dim myPath As New Path()
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
myPath.Data = myLineGeometry

A LineGeometry
Uma LineGeometry desenhada de (10,20) para (100,130)

Outras classes de geometria simples incluem LineGeometry e EllipseGeometry. Essas geometrias, assim como as mais complexas, também podem ser criadas usando um PathGeometry ou StreamGeometry. Para obter mais informações, consulte Visão geral de geometria.

Confira também