BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Windows Presentation Foundation
.NET 4.0+

WPF Shapes - Path - Path Geometry

The one hundred and twenty-seventh part of the Windows Presentation Foundation Fundamentals tutorial starts to look at path geometry. This provides the most flexible way to draw open or closed shapes. However, it is the most complex option.

Fill Options

When a path geometry is rendered within a path, the area can be filled with a colour or pattern defined using the Fill property of the path. You can also specify a fill rule using the PathGeometry's FillRule property. This allows selection from the same rules that we've seen previously.

In addition to the normal options, you can also specify whether each figure should be filled or not. By default, figures are filled. If you set their IsFilled property to false, the figure becomes transparent.

To demonstrate, update the PathGeometry as follows. This turns off the fill for the first figure.

<PathGeometry>
    <PathGeometry.Figures>
        <PathFigure StartPoint="100,50" IsClosed="True" IsFilled="False">
            <LineSegment Point="140,60"/>
            <LineSegment Point="150,100"/>
            <LineSegment Point="125,120"/>
            <LineSegment Point="90,110"/>
            <LineSegment Point="80,80"/>
        </PathFigure>
        <PathFigure StartPoint="20,40" IsClosed="True">
            <LineSegment Point="70,15"/>
            <LineSegment Point="80,30"/>
            <LineSegment Point="65,70"/>
            <LineSegment Point="80,115"/>
            <LineSegment Point="10,80"/>
        </PathFigure>
        <PathFigure StartPoint="140,40" IsClosed="True">
            <LineSegment Point="170,50"/>
            <LineSegment Point="180,90"/>
            <LineSegment Point="180,120"/>
            <LineSegment Point="140,150"/>
            <LineSegment Point="130,130"/>
            <LineSegment Point="160,100"/>
        </PathFigure>
    </PathGeometry.Figures>
</PathGeometry>

The result is shown below:

WPF Path Geometry Fill Options

Segment Types

In this article we've only used line segments. Over the next few articles we'll look at the other segment types, including arcs, two types of Bézier curve and line and curve series.

14 January 2015