Sdílet prostřednictvím


Postupy: Vytváření LineSegment v PathGeometry

Tento příklad ukazuje, jak vytvořit segment čáry. Chcete-li vytvořit segment čáry, použijte PathGeometry, PathFigurea LineSegment třídy.

Příklad

Následující příklady nakreslí LineSegment od (10, 50) do (200, 70). Následující obrázek znázorňuje výsledný LineSegment; pozadí mřížky bylo přidáno k zobrazení souřadnicového systému.

A LineSegment in a PathFigure A LineSegment nakreslený z (10 50) do (200,70)

V jazyce XAML (Extensible Application Markup Language) můžete k popisu cesty použít syntaxi atributů.

<Path Stroke="Black" StrokeThickness="1"
  Data="M 10,50 L 200,70" />

(Všimněte si, že tato syntaxe atributu ve skutečnosti vytvoří StreamGeometry, světlejší verzi . PathGeometry Další informace najdete na stránce Syntaxe značek cesty.)

V jazyce XAML můžete také nakreslit segment čáry pomocí syntaxe elementu objektu. Následující příklad odpovídá předchozímu příkladu 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

Tento příklad je součástí většího vzorku; pro úplný vzorek viz ukázka geometrie.

Viz také