방법: PathGeometry에 LineSegment 만들기

이 예제에서는 선분을 만드는 방법을 보여 줍니다. 선분은 PathGeometry, PathFigureLineSegment 클래스를 사용하여 만듭니다.

예제

다음 예제에서는 (10, 50)에서 (200, 70)까지 LineSegment를 그립니다. 다음 그림에서는 결과 LineSegment를 보여 줍니다. 모눈 배경이 좌표계를 표시하기 위해 추가되었습니다.

(10,50)에서 (200,700)까지 그려진 LineSegment

PathFigure의 LineSegment

[xaml]

Extensible Application Markup Language (XAML)에서는 특성 구문을 사용하여 경로를 나타낼 수 있습니다.

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

[xaml]

실제로 이 특성 구문은 PathGeometry의 단순화된 버전인 StreamGeometry를 만듭니다. 자세한 내용은 경로 태그 구문 페이지를 참조하십시오.

XAML에서는 개체 요소 구문을 사용하여 선분을 그릴 수도 있습니다. 다음은 앞의 XAML 예제와 동일합니다.

            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
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;
<Path Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <PathGeometry>
      <PathFigure StartPoint="10,50">
        <LineSegment Point="200,70" />
      </PathFigure>
    </PathGeometry>
  </Path.Data>
</Path>

이 예제는 큰 샘플의 일부입니다. 전체 샘플을 보려면 Geometries 샘플을 참조하십시오.

참고 항목

참조

PathFigure

PathGeometry

GeometryDrawing

Path

개념

Geometry 개요