Appendix F. Pens

This appendix summarizes Pens. A Pen defines the colors and geometry of linear features such as lines, paths, and the edges of drawn shapes like Rectangles.

Typically Pen properties are provided by some other object rather than the Pen itself and determine how the object defines its Pen.

For example, the Ellipse control's Stroke and StrokeThickness properties determine how the control draws its border. The following code draws an ellipse with a red border that's 10 pixels wide:

<Ellipse Width="200" Height="100" Stroke="Red" StrokeThickness="10"/>

Table F-1 summarizes Pen's key properties.

Table F.1. Key Properties of Pen

Property

Purpose

Stroke

Determines the Pen's Brush. This can be a solid color like red or an element attribute that specifies a more complicated brush such as a LinearGradientBrush.

StrokeDashArray

Determines the Pen's pattern of drawn and skipped segments in units of the pen's thickness. For example, the pattern 3,1 means "draw three pen widths, skip one pen width, and repeat."

StrokeDashCap

Determines the shape of the ends of each dash. This can be Flat, Round, Square, or Triangle.

StrokeDashOffset

Determines how far into the first dash the line starts.

StrokeEndLineCap

Determines the shape of the Pen's finishing end. This can be Flat, Round, Square, or Triangle.

StrokeLineJoin

Determines how the Pen draws corners. This can be Bevel, Miter, or Round.

StrokeMiterLimit

Determines how pointy a corner can be when two segments connect as in a Polygon.

StrokeStartLineCap ...

Get WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.