Chapter 6. Resources, styles, control templates, and themes

 

This chapter covers:

  • Resources
  • Styles
  • Control templates
  • Themes
  • The similarities between Windows XP and a certain children’s program

Even the title for this chapter is exhausting. It isn’t as bad as it sounds, though—all these topics are related. Styles let you combine a set of attributes together and give them a name. You can then apply that style to an element (such as a control). Control templates are special styles that apply to the look-and-feel and behavior of controls. Resources are blobs of content that you can store in your XAML. They relate to the other topics because styles are stored in resources, and control templates are just types of styles. A theme is a collection of styles that control the look-and-feel of an entire application, such as the Aero theme, which is the default for Windows Vista.

The topics in this chapter also form much of the basis for one of the key capabilities of WPF—the ability to easily separate UI from behavior. A graphic artist can provide a theme, a collection of styles and templates stored as resources that can be referenced by your code or can even override behavior of particular types of controls. The artist can edit these properties without touching code, and vice versa. You could give your XAML to your artist and let them edit that while you keep the supporting code separate, but that’s more risky. It would be too easy for important properties or handlers to go missing.

6.1. Resources

6.2. Styles

6.3. Control templates

6.4. Themes

6.5. Summary

sitemap