如何:使用 PathGeometry 创建形状

此示例演示如何使用 PathGeometry 类创建形状。 PathGeometry 对象由一个或多个 PathFigure 对象组成;每个 PathFigure 代表一个不同的“图形”或形状。 每个 PathFigure 自身又由一个或多个 PathSegment 对象组成,每个对象均表示图形或形状的已连接部分。 线段类型包括 LineSegmentArcSegmentBezierSegment

示例

下面的示例使用 PathGeometry 创建三角形。 PathGeometry 通过使用 Path 元素来显示。

<Path Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>
        <PathFigureCollection>
          <PathFigure IsClosed="True" StartPoint="10,100">
            <PathFigure.Segments>
              <PathSegmentCollection>
                <LineSegment Point="100,100" />
                <LineSegment Point="100,50" />
              </PathSegmentCollection>
            </PathFigure.Segments>
          </PathFigure>
        </PathFigureCollection>
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>

下面的插图演示在上一示例中创建的形状。

使用 PathGeometry 创建的三角形

一个 PathGeometry

上一示例演示了如何创建一个相对较简单的三角形形状。 PathGeometry 还可用于创建一些更为复杂的形状,包括弧线和曲线。 有关示例,请参见 如何:创建椭圆弧如何:创建三次方贝塞尔曲线如何:创建二次贝塞尔曲线

此示例摘自一个更大的示例;有关完整示例,请参见 Geometries Sample(几何图形示例)。

请参见

参考

Path

GeometryDrawing

概念

Geometry 概述

其他资源

Geometries Sample