# FillRule Enumeration

**.NET Framework 3.5**

Specifies how the intersecting areas of PathFigure objects contained in a Geometry are combined to form the area of the Geometry.

**Namespace:**System.Windows.Media

**Assembly:**PresentationCore (in PresentationCore.dll)

Member name | Description | |
---|---|---|

EvenOdd | Rule that determines whether a point is in the fill region by drawing a ray from that point to infinity in any direction and counting the number of path segments within the given shape that the ray crosses. If this number is odd, the point is inside; if even, the point is outside. | |

Nonzero | Rule that determines whether a point is in the fill region of the path by drawing a ray from that point to infinity in any direction and then examining the places where a segment of the shape crosses the ray. Starting with a count of zero, add one each time a segment crosses the ray from left to right and subtract one each time a path segment crosses the ray from right to left. After counting the crossings, if the result is zero then the point is outside the path. Otherwise, it is inside. |

The FillRule property of a GeometryGroup or a PathGeometry, specifies a "rule" which the composite shape uses to determine whether a given point is part of the geometry. There are two possible values for FillRule: EvenOdd and Nonzero. The following sections will describe how to use these two rules.

**EvenOdd:** This rule determines whether a point is in the fill region by drawing a ray from that point to infinity in any direction and counting the number of path segments within the given shape that the ray crosses. If this number is odd, the point is inside; if even, the point is outside.

For example, the XAML below creates a composite shape made up of a series of concentric rings (target) with a FillRule set to EvenOdd.

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF"> <Path.Data> <GeometryGroup FillRule="EvenOdd"> <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" /> <EllipseGeometry RadiusX="70" RadiusY="70" Center="75,75" /> <EllipseGeometry RadiusX="100" RadiusY="100" Center="75,75" /> <EllipseGeometry RadiusX="120" RadiusY="120" Center="75,75" /> </GeometryGroup> </Path.Data> </Path>

The following illustration shows the shape created in the previous example.

In the illustration above, notice that the center and 3rd ring are not filled. This is because a ray drawn from any point within either of those two rings passes through an even number of segments. See illustration below:

**NonZero:** This rule determines whether a point is in the fill region of the path by drawing a ray from that point to infinity in any direction and then examining the places where a segment of the shape crosses the ray. Starting with a count of zero, add one each time a Segment crosses the ray from left to right and subtract one each time a path segment crosses the ray from right to left. After counting the crossings, if the result is zero then the point is outside the path. Otherwise, it is inside.

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF"> <Path.Data> <GeometryGroup FillRule="NonZero"> <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" /> <EllipseGeometry RadiusX="70" RadiusY="70" Center="75,75" /> <EllipseGeometry RadiusX="100" RadiusY="100" Center="75,75" /> <EllipseGeometry RadiusX="120" RadiusY="120" Center="75,75" /> </GeometryGroup> </Path.Data> </Path>

Using the example above, a value of Nonzero for FillRule gives the following illustration as a result:

As you can see, all the rings are filled. This is because all the segments are running in the same direction and so a ray drawn from any point will cross one or more segments and the sum of the crossings will not equal zero. For example, in the illustration below, the red arrows represent the direction the segments are drawn and the white arrow represents an arbitrary ray running from a point in the innermost ring. Starting with a value of zero, for each segment that the ray crosses, a value of one is added because the segment crosses the ray from left to right.

To better demonstrate the behavior of Nonzero rule a more complex shape with segments running in different directions is required. The XAML code below creates a similar shape as the previous example except that it is created with a PathGeometry rather then a EllipseGeometry which creates four concentric arcs rather then fully closed concentric circles.

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF"> <Path.Data> <GeometryGroup FillRule="NonZero"> <PathGeometry> <PathGeometry.Figures> <!-- Inner Ring --> <PathFigure StartPoint="10,120"> <PathFigure.Segments> <PathSegmentCollection> <ArcSegment Size="50,50" IsLargeArc="True" SweepDirection="CounterClockwise" Point="25,120" /> </PathSegmentCollection> </PathFigure.Segments> </PathFigure> <!-- Second Ring --> <PathFigure StartPoint="10,100"> <PathFigure.Segments> <PathSegmentCollection> <ArcSegment Size="70,70" IsLargeArc="True" SweepDirection="CounterClockwise" Point="25,100" /> </PathSegmentCollection> </PathFigure.Segments> </PathFigure> <!-- Third Ring (Not part of path) --> <PathFigure StartPoint="10,70"> <PathFigure.Segments> <PathSegmentCollection> <ArcSegment Size="100,100" IsLargeArc="True" SweepDirection="CounterClockwise" Point="25,70" /> </PathSegmentCollection> </PathFigure.Segments> </PathFigure> <!-- Outer Ring --> <PathFigure StartPoint="10,300"> <PathFigure.Segments> <ArcSegment Size="130,130" IsLargeArc="True" SweepDirection="Clockwise" Point="25,300" /> </PathFigure.Segments> </PathFigure> </PathGeometry.Figures> </PathGeometry> </GeometryGroup> </Path.Data> </Path>

The following illustration shows the shape created in the previous example.

Notice that the third arc from the center is not filled. The illustration below shows why this is. In the illustration, the red arrows represent the direction the segments are drawn. The two white arrows represent two arbitrary rays that move out from a point in the "non-filled" region. As can be seen from the illustration, the sum of the values from a given ray crossing the segments in its path is zero. As defined above, a sum of zero means that the point is not part of the geometry (not part of the fill) while a sum that is *not* zero, including a negative value, is part of the geometry.

**Note:** For the purposes of FillRule, all shapes are considered closed. If there is a gap in a segment, draw an imaginary line to close it. In the example above, there are small gaps in the rings. Given this, one might expect a ray that runs through the gap to give a different result then a ray running in another direction. Below is an enlarged illustration of one of these gaps and the "imaginary segment" (segment that is drawn for purposes of applying the FillRule) that closes it.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.