Aracılığıyla paylaş


Nasıl yapılır: PathGeometry İçinde LineSegment Oluşturma

Bu örnekte bir çizgi kesiminin nasıl oluşturulacağı gösterilmektedir. Satır kesimi oluşturmak için , PathFigureve LineSegment sınıflarını kullanınPathGeometry.

Örnek

Aşağıdaki örneklerde (10, 50) ile (200, 70) arasında bir LineSegment çizim yapılır. Aşağıdaki çizimde elde LineSegmentedilen ; koordinat sistemini göstermek için bir kılavuz arka planı eklenmiştir.

A LineSegment in a PathFigure (10,50) ile (200,70) arasında bir LineSegment çizildi

Genişletilebilir Uygulama Biçimlendirme Dili'nde (XAML), bir yolu açıklamak için öznitelik söz dizimi kullanabilirsiniz.

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

(Bu öznitelik söz diziminin aslında bir StreamGeometry' nin PathGeometrydaha hafif bir sürümünü oluşturduğunu unutmayın. Daha fazla bilgi için Yol İşaretlemeyi Söz Dizimi sayfasına bakın.)

XAML'de, nesne öğesi söz dizimini kullanarak bir çizgi kesimi de çizebilirsiniz. Aşağıdaki, önceki XAML örneğine eşdeğerdir.

<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

Bu örnek daha büyük bir örneğin parçasıdır; Örneğin tamamı için bkz . Geometries Örneği.

Ayrıca bkz.