共用方式為


如何:建立三次方貝茲曲線

此範例顯示如何建立三次方貝茲曲線。 若要建立三次方貝茲曲線,請使用 PathGeometryPathFigureBezierSegment 類別。 若要顯示產生的幾何,請使用 Path 元素,或將其與 GeometryDrawingDrawingContext 搭配使用。 在下列範例中,從 (10, 100) 到 (300, 100) 繪製三次方貝茲曲線。 曲線的控制點為 (100, 0) 和 (200, 200)。

範例

在 Extensible Application Markup Language (XAML) 中,您可能會使用縮寫標記語法來描述路徑。

<Path Stroke="Black" StrokeThickness="1"  
  Data="M 10,100 C 100,0 200,200 300,100" />

在 XAML 中,您也可以使用物件標記來繪製三次方貝茲曲線。 下列相當於先前的 XAML 範例。

<Path Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>
        <PathFigureCollection>
          <PathFigure StartPoint="10,100">
            <PathFigure.Segments>
              <PathSegmentCollection>
                <BezierSegment Point1="100,0" Point2="200,200" Point3="300,100" />
              </PathSegmentCollection>
            </PathFigure.Segments>
          </PathFigure>
        </PathFigureCollection>
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>

這個範例屬於較大型的範例;如需完整範例,請參閱幾何範例

另請參閱