In
essence, this code grabs a snapshot of the current color or brush. To make sure your program
can update itself in response to configuration changes, you need to use dynamic resources,
as described in Chapter 11.
The Colors and SystemColors classes offer handy shortcuts, but they??™re not the only way
to set a color. You can also create a Color object by supplying the R, G, B values (red, green,
and blue). Each one of these values is a number from 0 to 255:
Dim red As Integer = 0
Dim green As Integer = 255
Dim blue As Integer = 0
cmd.Foreground = New SolidColorBrush(Color.FromRgb(red, green, blue))
You can also make a color partly transparent by supplying an alpha value and calling the
Color.FromArgb() method. An alpha value of 255 is completely opaque, while 0 is completely
transparent.
RGB AND SCRGB
The RGB standard is useful because it??™s used in many other programs??”for example, you can get the RGB
value of a color in a graphic in a paint program and use the same color in your WPF application. However, it??™s
possible that other devices (such as printers) might support a richer range of colors. For this reason, an alternative
scRGB standard has been created that represents each color component (alpha, red, green, and blue)
using 64-bit values.
The WPF Color structure supports either approach.
Pages:
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361