Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
Este exemplo mostra como criar um segmento de linha. Para criar um segmento de linha, use as classes PathGeometry, PathFiguree LineSegment.
Exemplo
Os exemplos a seguir desenham um LineSegment de (10, 50) até (200, 70). A ilustração a seguir mostra o LineSegmentresultante; um plano de fundo de grade foi adicionado para mostrar o sistema de coordenadas.
Um LineSegment desenhado de (10,50) para (200,70)
Em XAML (Extensible Application Markup Language), você pode usar a sintaxe de atributo para descrever um caminho.
<Path Stroke="Black" StrokeThickness="1"
Data="M 10,50 L 200,70" />
(Observe que a sintaxe de atributo mencionada realmente cria um StreamGeometry, uma versão mais leve de um PathGeometry. Para obter mais informações, consulte a página Sintaxe de Marcação de Caminho.)
No XAML, você também pode desenhar um segmento de linha usando a sintaxe do elemento de objeto. A seguir, é equivalente ao exemplo XAML anterior.
<Path Stroke="Black" StrokeThickness="1">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="10,50">
<LineSegment Point="200,70" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new Point(10, 50);
LineSegment myLineSegment = new LineSegment();
myLineSegment.Point = new Point(200, 70);
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(myLineSegment);
myPathFigure.Segments = myPathSegmentCollection;
PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;
Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;
Dim myPathFigure As New PathFigure()
myPathFigure.StartPoint = New Point(10, 50)
Dim myLineSegment As New LineSegment()
myLineSegment.Point = New Point(200, 70)
Dim myPathSegmentCollection As New PathSegmentCollection()
myPathSegmentCollection.Add(myLineSegment)
myPathFigure.Segments = myPathSegmentCollection
Dim myPathFigureCollection As New PathFigureCollection()
myPathFigureCollection.Add(myPathFigure)
Dim myPathGeometry As New PathGeometry()
myPathGeometry.Figures = myPathFigureCollection
Dim myPath As New Path()
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
myPath.Data = myPathGeometry
Este exemplo faz parte de uma amostra maior; para obter o exemplo completo, consulte o exemplo de geometrias .
Consulte também
- PathFigure
- PathGeometry
- GeometryDrawing
- Path
- Visão geral da geometria
.NET Desktop feedback