Prev | Current Page 621 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

However, life??™s not usually
that easy. For example, you may want to give all buttons a consistent typeface and text size
independent from the font settings that are used in other elements. In this case, you need a
way to define these details in one place and reuse them wherever they apply.
Resources give you a solution, but it??™s somewhat awkward. Because there??™s no Font object
in WPF (just a collection of font-related properties), you??™re stuck defining several related
resources, as shown here:

Times New Roman
18
Bold

This snippet or markup adds three resources to a window: a FontFamily object with the
name of the font you want to use, a Double that stores the number 18, and the enumerated
value FontWeight.Bold. It assumes you??™ve mapped the .NET namespace System to the XML
namespace prefix sys, as shown here:

nTip When setting properties using a resource, it??™s important that the data types match exactly. WPF won??™t
use a type converter in the same way it does when you set an attribute value directly. For example, if you??™re
setting the FontFamily attribute in an element, you can use the string ???Times New Roman??? because the Font-
FamilyConverter will create the FontFamily object you need.


Pages:
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633