Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In the previous chapter you learned about the WPF resource system, which lets you define objects in one place and reuse them throughout your markup. Although you can use resources to store a wide variety of objects, one of the most common reasons you'll use them is to hold styles.
A style is a collection of property values that can be applied to an element. The WPF style system plays a similar role to the cascading style sheet (CSS) standard in HTML markup. Like CSS, WPF styles allow you to define a common set of formatting characteristics and apply them throughout your application to ensure consistency. And as with CSS, WPF styles can work automatically, target specific element types, and cascade through the element tree. However, WPF styles are more powerful because they can set any dependency property. That means you can use them to standardize nonformatting characteristics, such as the behavior of a control. WPF styles also support triggers, which allow you to change the style of a control when another property is changed (as you'll see in this chapter), and they can use templates to redefine the built-in appearance of a control (as you'll see in Chapter 15). Once you've learned how to use styles, you'll be sure to include them in all your WPF applications.