Notes
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Cet exemple montre comment créer un segment de ligne. Pour créer un segment de ligne, utilisez les classes PathGeometry, PathFigureet LineSegment.
Exemple :
Les exemples suivants dessinent une LineSegment de (10, 50) à (200, 70). L’illustration suivante montre la LineSegmentrésultante ; un arrière-plan de grille a été ajouté pour afficher le système de coordonnées.
LineSegment tracé de (10,50) à (200,70)
Dans XAML (Extensible Application Markup Language), vous pouvez utiliser la syntaxe d’attribut pour décrire un chemin d’accès.
<Path Stroke="Black" StrokeThickness="1"
Data="M 10,50 L 200,70" />
(Notez que cette syntaxe d’attribut crée en fait un
En XAML, vous pouvez également dessiner un segment de ligne à l’aide de la syntaxe de l’élément objet. Voici l’équivalent de l’exemple XAML précédent.
<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
Cet exemple fait partie d'un échantillon plus vaste ; pour obtenir l'échantillon complet, consultez l’échantillon de géométries .
Voir aussi
- PathFigure
- PathGeometry
- GeometryDrawing
- Path
- Vue d’ensemble de la géométrie
.NET Desktop feedback