You could improve on the first issue by defining a custom class (such as FontSettings)
that bundles all the font details together. You could then create one FontSettings object as
a resource and use its various properties in your markup. However, this still leaves you with
verbose markup??”and it makes for a fair bit of extra work.
Styles provide the perfect solution. You can define a single style that wraps all the properties
you want to set. Here??™s how:
This markup creates a single resource: a System.Windows.Style object. This style object
holds a Setters collection with three Setter objects, one for each property you want to set. Each
Setter object names the property that it acts on and the value that it applies to that property.
Like all resources, the style object has a key name so you can pull it out of the collection when
needed. In this case, the key name is BigFontButtonStyle. (By convention, the key names for
styles usually end with ???Style.???)
Every WPF element can use a single style (or no style). The style plugs into an element
through the element??™s Style property (which is defined in the base FrameworkElement class).
Pages:
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635