Background = New SolidColorBrush(Colors.AliceBlue)
This code creates a new SolidColorBrush using a ready-made color via a shared property
of the handy Colors class. (The names are based on the color names supported by most web
browsers.) It then sets the brush as the background brush for the button, which causes its
background to be painted a light shade of blue.
nNote This method of styling a button isn??™t completely satisfactory. If you try it, you??™ll find that it configures
the background color for a button in its normal (unpressed) state, but it doesn??™t change the color that
appears when you press the button (which is a darker gray). To really customize every aspect of a button??™s
appearance, you need to delve into templates, as discussed in Chapter 15.
You can also grab system colors (which may be based on user preferences) from the
System.Windows.SystemColors enumeration. Here??™s an example:
cmd.Background = New SolidColorBrush(SystemColors.ControlColor)
Because system brushes are used frequently, the SystemColors class also provides
ready-made properties that return SolidColorBrush objects. Here??™s how you use them:
cmd.Background = SystemColors.ControlBrush
As it??™s written, both of these examples suffer from a minor problem. If the system color is
changed after you run this code, your button won??™t be updated to use the new color.
Pages:
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360