12.2. Brushes

Brushes fill an area—whether it's the background, foreground, or border of an element, or the fill or stroke of a shape. The simplest type of brush is SolidColorBrush, which paints a solid, continuous color. When you set the Stroke or Fill property of a shape in XAML, there's a SolidColorBrush at work, doing the painting behind the scenes.

Here are a few more fundamental facts about brushes:

  • Brushes support change notification because they derive from Freezable. As a result, if you change a brush, any elements that use that brush repaint themselves automatically.

  • Brushes support partial transparency. All you need to do is modify the Opacity property to let the background show through. You'll try out this approach at the end of this ...

Get Pro WPF in C# 2010: Windows Presentation Foundation in .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.