Uwaga
Dostęp do tej strony wymaga autoryzacji. Może spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
W tym przykładzie pokazano, jak utworzyć segment wiersza. Aby utworzyć segment liniowy, użyj klas PathGeometry, PathFigurei LineSegment.
Przykład
W poniższych przykładach przedstawiono LineSegment od (10, 50) do (200, 70). Poniższa ilustracja przedstawia wynikowe LineSegment; Dodano tło siatki w celu pokazania układu współrzędnych.
Odcinek narysowany od (10, 50) do (200, 70)
W języku Extensible Application Markup Language (XAML) można użyć składni atrybutów do opisania ścieżki.
<Path Stroke="Black" StrokeThickness="1"
Data="M 10,50 L 200,70" />
(Należy pamiętać, że ta składnia atrybutu faktycznie tworzy StreamGeometry, lżejszą wersję PathGeometry. Aby uzyskać więcej informacji, zobacz stronę dotyczącą składni znaczników ścieżki ).
W języku XAML można również narysować segment wiersza przy użyciu składni elementu obiektu. Poniższy kod jest odpowiednikiem poprzedniego przykładu XAML.
<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
Ten przykład jest częścią większej próbki; Aby zapoznać się z kompletnym przykładem, zobacz przykład Geometries.
Zobacz też
.NET Desktop feedback