(Chapter 5 covered content and alignment,
while Chapter 6 explored the subtleties of focus and tab order.) The following sections
cover brushes and fonts.
Background and Foreground Brushes
All controls include the concept of a background and foreground. Usually, the background is
the surface of the control (think of the white or gray area inside the borders of a button), while
the foreground is the text. In WPF, you set the color of these two areas (but not the content)
using the Background and Foreground properties.
It??™s natural to expect that the Background and Foreground properties would use color
objects, as they do in a Windows Forms application. However, these properties actually use
something much more versatile: a Brush object. That gives you the flexibility to fill your background
and foreground content with a solid color (by using the SolidColorBrush) or something 183
C H A P T E R 7
184 CHAPTER 7 n CLASSIC CONTROLS
more exotic (for example, by using a LinearGradientBrush or TileBrush). In this chapter, you??™ll
consider only the simple SolidColorBrush, but you??™ll try fancier brushwork in Chapter 13.
nNote All Brush classes are found in the System.Windows.Media namespace.
Setting Colors in Code
Imagine you want to set a blue surface area inside a button named cmd. Here??™s the code that
does the trick:
cmd.
Pages:
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359