この例では、線分を作成する方法を示します。 線分を作成するには、PathGeometry、PathFigure、および LineSegment クラスを使用します。
例
次の例では、(10, 50) から (200, 70) までの LineSegment を描画します。 次の図は、結果の LineSegmentを示しています。座標系を表示するためにグリッドの背景が追加されました。
(10,50) から (200,70) まで描画された LineSegment
拡張アプリケーション マークアップ言語 (XAML) では、属性構文を使用してパスを記述できます。
<Path Stroke="Black" StrokeThickness="1"
Data="M 10,50 L 200,70" />
(この属性構文は、実際には StreamGeometryの軽量バージョンである PathGeometryを作成します。詳細については、「パス マークアップ構文 ページ」を参照してください。
XAML では、オブジェクト要素の構文を使用してライン セグメントを描画することもできます。 次は、前の 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
この例は、より大きなサンプルの一部です。完全なサンプルについては、Geometries サンプルを参照してください。
こちらも参照ください
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET Desktop feedback