Home  separator  Styling
Bookmark and Share Share...    Subscribe to this feed Feed   About Christian Moser  


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

Learn more about Templates



Last modified: 2011-05-03 10:40:49
Copyright (c) by Christian Moser, 2011.

 Comments on this article

Show all comments
Andre
Commented on 9.August 2010
Very clear article, as is the case for all those I've happened upon on the site so far. I was real interested in getting more information about templates though, but it turns out the link is broken...(http://www.wpftutorial.net/Templates.html)
elhuus
Commented on 18.May 2011
Hi very interesting stuff on your site would be great to have a download attached to some of the articles that might need it.
I believe WPF styles and themes could have been better with a simpler syntax (a CSS like syntax) than with the xml format just as they did for binding syntax.
thanks for the great help and articles you provide
andre
Commented on 26.July 2011
wpf

Name
E-Mail (optional)
Comment