StreamGeometryContext.QuadraticBezierTo Method (Point, Point, Boolean, Boolean)

 

Draws a quadratic Bezier curve.

Namespace:   System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

public abstract void QuadraticBezierTo(
	Point point1,
	Point point2,
	bool isStroked,
	bool isSmoothJoin
)

Parameters

point1
Type: System.Windows.Point

The control point used to specify the shape of the curve.

point2
Type: System.Windows.Point

The destination point for the end of the curve.

isStroked
Type: System.Boolean

true to make the segment stroked when a Pen is used to render the segment; otherwise, false.

isSmoothJoin
Type: System.Boolean

true to treat the join between this segment and the previous segment as a corner when stroked with a Pen; otherwise, false.

Exception Condition
InvalidOperationException

An attempt was made to add a segment without starting a figure by calling the BeginFigure method.

Unlike a cubic Bezier curve, which uses two control points, a quadratic cubic Bezier curve uses a single control point.

This method uses the end point of the previous segment as its starting point. If this is the first segment in a figure, it uses the point specified by the BeginFigure method as its start point.

A StreamGeometry cannot be serialized if it contains a Transform or any non-stroked or unfilled segments.

The following example shows how to draw a quadratic Bezier curve using the QuadraticBezierTo method.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace SDKSample
{
    public partial class StreamGeometryQuadraticBezierToExample : Page
    {
        public StreamGeometryQuadraticBezierToExample()
        {
            // Create a path to draw a geometry with.
            Path myPath = new Path();
            myPath.Stroke = Brushes.Black;
            myPath.StrokeThickness = 1;

            // Create a StreamGeometry to use to specify myPath.
            StreamGeometry geometry = new StreamGeometry();

            // Open a StreamGeometryContext that can be used to describe this StreamGeometry 
            // object's contents.
            using (StreamGeometryContext ctx = geometry.Open())
            {
                // Set the begin point of the shape.
                ctx.BeginFigure(new Point(10, 100), true /* is filled */, false /* is closed */);

                // Create a Quadratic Bezier curve using the 2 specifed points. The first point
                // specifies the control point while the second point specifies the end point 
                // of the curve.
                ctx.QuadraticBezierTo(new Point(100, 0), new Point(200, 200), true /* is stroked */, 
                                      false /* is smooth join */);

            }

            // Freeze the geometry (make it unmodifiable)
            // for additional performance benefits.
            geometry.Freeze();

            // specify the shape (quadratic Bezier curve) of the path using the StreamGeometry.
            myPath.Data = geometry;

            // Add path shape to the UI.
            StackPanel mainPanel = new StackPanel();
            mainPanel.Children.Add(myPath);
            this.Content = mainPanel;
        }
    }
}

.NET Framework
Available since 3.0
Return to top
Show: