A Shape is a type of UIElement that enables you to draw a shape to the screen. Because they are UI elements, Shape objects can be used inside Panel elements and most controls.
WPF offers several layers of access to graphics and rendering services. At the top layer, Shape objects are easy to use and provide many useful features, such as layout and participation in the WPF event system.
WPF provides a number of ready-to-use Shape objects. All shape objects inherit from the Shape class. Available shape objects include Ellipse, Line, Path, Polygon, Polyline, and Rectangle.
You can use Path to generate a bezier curve.
There are two types of path segment that you can use to draw Bézier curves. These are a special type of smooth curve, calculated mathematically using fixed start and end points, and one or more control points, known as tangent points.
The tangent points determine the path of the curve. If you draw a line with a single tangent point, the direction of travel at the start and end of the curve will point directly towards that point. With more control points, the curve becomes more complex.
WPF can render Bézier curves with one or two control points.
To create a Bézier curve with a single tangent point, you can add a QuadraticBezierSegment to a PathGeometry. As with other segments, the curve starts from the end point of the previous segment, or from the Path's start point if the curve is the first segment. The co-ordinates of the start point are set in the Point1 property and the end point of the curve is held in Point2.
<Window x:Class="BezierSegmentDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF Path Demo"
Height="200" Width="250">
<Canvas>
<Path Stroke="#C0000000" StrokeThickness="3">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="20,100" IsClosed="False">
<QuadraticBezierSegment Point1="80,150" Point2="200,20"/>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
<Ellipse Canvas.Left="75" Canvas.Top="145" Fill="Blue" Height="10" Width="10" />
</Canvas>
To create a curve with two tangent points, you can include a BezierSegment element. These require three properties. Point1 and Point2 define the control points. Point3 determines the co-ordinates of the end of the line.
<Canvas>
<Path Stroke="#C0000000" StrokeThickness="3">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="20,20" IsClosed="False">
<BezierSegment Point1="70,130" Point2="220,20" Point3="180,160"/>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
<Ellipse Canvas.Left="65" Canvas.Top="125" Fill="Blue" Height="10" Width="10" />
<Ellipse Canvas.Left="215" Canvas.Top="15" Fill="Blue" Height="10" Width="10" />
</Canvas>
To have a line with varying thickness you can actually create two or more lines with a thickness thick enough to overlap more or less at different points along the curve. Imagine if you slightly alter the curve of a second line so that the two lines completely overlap one place so the thickness is the thickness of just one line but where they just touch at another point so that the thickness is twice the stroke width.
You could also create a closed path with fill.
<border />
and give itheight
andwidth
(can be same or different) and set theCornerRadius
property of it, to give you the rounded edges. The second part I'm sure you can figure out for yourself. Tip: please provide some code of things you've tried already in your OP. See here: stackoverflow.com/help/how-to-ask – Geoff James