This article continues from Graphics in Silverlight 5 - Part I, Part II, and Part III.

In the fourth part of this series, we shall explore the Path element.

Path

The Path element enables you to draw a series of graphic elements such as curves and lines. The line and curve dimensions are declared through a Data property, and are commonly specified using a mini-markup language.

The basic XAML syntax for the Path element consists of an optional FillRule value and one or more figure descriptions.

<Path>
< object property ="[fillRule] figureDescription[ figureDescription]*" ... />
</Path>

A few simple elements comprising the path markup mini-language are as follows:

The outcome of this is shown in Figure 1.



Figure 1

The following markup creates a cubic Bezier curve.

<Path Stroke="Magenta" StrokeThickness="3" Data="M 20,20 S 100,200 400,20" />

The outcome of this is shown in Figure 2.



Figure 2

The following markup draws a quadratic bezier curve.

<Path Stroke="Orange"
StrokeThickness="3" Data="M 20, 60 q 50,90 0,40" />

The output is shown in Figure 3.



Figure 3

As shown so far, the Path class has a single property, Data, which accepts a Geometry object defining one or more shapes the path includes. Geometries can be considered to be of two types: simple geometries and complex geometries. The LineGeometry, RectangleGeometry, and EllipseGeometry classes map directly to the Line,Rectangle, and Ellipse shapes and are simple geometries. GeometryGroup and PathGeometry are complex geometries. These are briefly described as follows:

A complex example of PathGeometry is shown below:

<Path Stroke="DarkOliveGreen" StrokeThickness="4" >
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="50,50">
<PathFigure.Segments>
<BezierSegment Point1="100,30"
Point2="200,250"
Point3="300,150"/>
<LineSegment Point="400,10" />
<ArcSegment Size="50,50" RotationAngle="45"
IsLargeArc="True" SweepDirection="Clockwise"
Point="150,150"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>

The output is shown in Figure 4.



Figure 4

Conclusion: The fourth part of this series introduced the Path element.

Continue to next part >>