WPF Templates: Styles and Triggers on Steroids

Posted on 3/5/2007 @ 1:18 AM in #Silverlight and WPF by | Feedback | 10906 views

Okay, I really couldn't think of a catchy title to fully describe the extent of the power of WPF Templates. So I just said "Styles and Triggers on Steroids".

Templates in WPF allow you to fully change the UI of anything in WPF. In WPF, Templates inherit from an Abstract base class called "FrameworkTemplate". This is shown as below -


As you can tell from the above figure, there are 4 kinds of Templates available within WPF.

1. ControlTemplate - You use this, when you want to completely redefine the visual appearance of any control. Say, you don't want a radiobutton to look like a radiobutton - you want it to look like a smiley instead. Smiling means Checked, and Frowning means Unchecked. You could easily acheive this using ControlTemplate.

2. ItemsPanelTemplate - Is a rather simple kind of template, it lets you control the appearance of the "ItemsPanel" property defined by "ItemsControl" on elements such as ListBox or ComboBox.

3. DataTemplate - is probably the most common kind of template you will use. It lets you change how "Content" is rendered on any control. So if you have an object called "Customer" and you want to define a standard look and feel for "Customer" - you'd use DataTemplate.

3.a. HierarchicalDataTemplate - is a class that is a DataTemplate that is very well suited to hierarchical data.

Sound off but keep it civil:

Older comments..

On 9/16/2008 8:35:21 PM Your Friend said ..
Thank you for a wonderfull blog. You dont need a catchy title, you have me.

On 9/16/2008 9:39:21 PM Sahil Malik said ..
I like having friends. Mind identifying yourself?

On 11/2/2009 1:05:05 PM Matt said ..
You had the other commenter at "WPF Templates". Great post, was very helpful.