Chapter 10. Pens and Brushes

Pens and brushes determine some of the most visually obvious pieces of a graphical application — its colors.

In graphical programming terms, a pen determines the color and style of a linear feature such as a line or the edge of a circle. A brush determines how an area is filled. For example, the ellipse drawn in Figure 10-1 is filled with a red brush and outlined with a thick, dashed, purple pen.

Figure 10-1

Figure 10.1. Figure 10-1

This chapter describes pen and brush properties and tells how to set them in XAML code. It explains the different kinds of pens and brushes and the properties that determine their appearance.

Pens

A pen defines the color and geometry of a linear feature such as a line, a curve defined by a Path control, or the edges of an ellipse or rectangle.

Interestingly, some colors that you might think would be determined by a pen are actually determined by a brush. In particular, text is rendered by filling the font's shapes with a brush rather than drawing the shapes with a pen. This is a bit counterintuitive if you think of drawing text by hand, where you usually use a pen (or a pencil or crayon, but probably not a brush unless you're practicing your Japanese calligraphy).

A pen has several different properties — all with names beginning with the word stroke — that determine its color and geometry.

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.