如何:创建椭圆弧
此示例演示如何绘制椭圆弧。 若要创建椭圆弧,请使用 PathGeometry、PathFigure 和 ArcSegment 类。
示例
在下面的示例中,椭圆弧是从 (10,100) 到 (200,100) 绘制而成的。 该弧的 Size 为 100 x 50 个与设备无关的像素、RotationAngle 为 45 度、IsLargeArc 设置为 true、SweepDirection 为 Counterclockwise。
[xaml]
在Extensible Application Markup Language (XAML) 中,可以使用特性语法来描述路径。
<Path Stroke="Black" StrokeThickness="1"
Data="M 10,100 A 100,50 45 1 0 200,100" />
[xaml]
(请注意,此特性语法实际上会创建一个 StreamGeometry(PathGeometry 的轻量版本)。 有关更多信息,请参见路径标记语法页。)
在 XAML 中,还可以通过显式使用对象标记来绘制椭圆弧。 下面的内容等效于前面的 XAML 标记。
<Path Stroke="Black" StrokeThickness="1">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="10,100">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment Size="100,50" RotationAngle="45" IsLargeArc="True" SweepDirection="CounterClockwise" Point="200,100" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
此示例摘自一个更大的示例。 有关完整示例,请参见 Geometries Sample(几何示例)。