업데이트: 2007년 11월
이 예제에서는 선분을 만드는 방법을 보여 줍니다. 선분은 PathGeometry, PathFigure 및 LineSegment 클래스를 사용하여 만듭니다.
예제
다음 예제에서는 (10, 50)에서 (200, 70)까지 LineSegment를 그립니다. 다음 그림에서는 이렇게 그려진 LineSegment를 보여 줍니다. 이 그림에서는 좌표계를 나타내기 위해 모눈 배경이 추가되었습니다.
(10,50)에서 (200,700)까지 그려진 LineSegment
xaml
XAML(Extensible Application Markup Language)에서는 특성 구문을 사용하여 경로를 나타낼 수 있습니다.
<Path Stroke="Black" StrokeThickness="1"
Data="M 10,50 L 200,70" />
xaml
실제로 이 특성 구문은 PathGeometry의 단순화된 버전인 StreamGeometry를 만듭니다. 자세한 내용은 경로 태그 구문 페이지를 참조하십시오.
XAML에서는 개체 요소 구문을 사용하여 선분을 그릴 수도 있습니다. 다음은 앞의 XAML 예제와 동일합니다.
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>
이 예제는 보다 큰 샘플의 일부입니다. 전체 샘플은 기하 도형 샘플을 참조하십시오.