如何:使用 PathGeometry 创建形状

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

示例:

以下示例使用 a 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 创建的三角形

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

此示例是较大示例的一部分;有关完整示例,请参阅 几何图形示例

另请参阅