Templates and Styles WPF.

Templates and Styles

One of WPF's most powerful feature is the ability to completely replace the look and feel of user interface elements.

Styles

The concept of styles let you remove all properties values from the individual user interface elements and combine them into a style. A style consists of a list of property setters. If you apply a style it sets the properties on the user interface element to the styles' values. The idea is quite similar to Cascading Styles Sheets (CSS) in web development.
Using styles gives you the following advantages:
  • Removes redundancy from your code
  • Let you change the appearance of a set of controls from a single point
  • Gives you the possibility to swap the style at runtime
Learn more about Styles

Templates

An element like a button consists of multpiple composed parts: A border, a chrome and a content presenter. With styles you can only change the appearance from "outside" by setting public properties. With a template you can replace parts inside a user interface element..
Using templates gives you the following advantages:
  • Change the parts inside a user interface element
  • Reduce the numbers custom controls

Comments