Someone asked me the other day with a lot of confusion a question, and I had to think about why it might be asked.. But a lot of design people don’t understand the programmer’s concept of “inheritance” amongst other things and why certain control elements have certain properties others don’t. Also why there are template modifications needed in some controls and not others. So I decided to try to break this down into bullet points:
STYLES
When you use a style you can modify what are the default values of a control properties. A simple example of this is specifying a default foreground color on the control (name the control a window, a button, etc.)
In programmer’s terms when we do this we are “overriding the control’s default property values”. When you do this the changes to the control you just modified are instant.
TEMPLATES
A template is just what it sounds like in real life. A template can be thought of as a guide to the structure of how something should look. If you were to make your own shirt you’d probably start by getting cloth and a pattern at your local fabric store and cut out the pattern. A template is pretty much the same idea with a control. It defines the structure. How it’s different from just changing values in a style is you can add new elements (parts) like adding an image to a button that didn’t already have one. In addition to everything you can do to modify the built in properties of a control you can add or extend it more.
If you apply a template to a control, know that just going back and setting new values on the control directly. You’d have to edit the control template or a copy of it and reapply the new template you just made to change things.
a useful control template is usually made up of several parts:
ContentPresenter
-
Note: This is the most misunderstood control element.
-
REPEAT after me: This is not necessarily a text field. It is a placeholder for a control that uses a control template to display it’s content and is flexible about the layout of that content. If you see a content presenter in a control that you need to change be ready for the fact that you are going to be editing a template to style the information presented in it. Sometimes it’s just text but most of the time there is formatting.
-
-
Header
A header is simply a label on a control. Usually a text field though like a content field it’s usually databind-able. An example of a “Header” is a tab control with text at the top. The text of that being the header.
ItemsHost
This is simply a placeholder for child elements in a control. In Blend you will notice there is a property called IsItemsHost if you set that to true, all will be good with the control.
ItemContainerTemplate
This is a template which is applied to a control that contains items like a list or a menu control. When you add items it to the control contain it creates one of these templates or adds to the existing one..
How do triggers work and relate?
Well a trigger lets you specify the behavior of any new or existing parts of a template. You could specify a trigger so that when a user moves the pointer over a button the color of the button or a part of it will change. These types of property changes/mods are instantly done. You can use this to animate a part and create a smooth transition.
You can’t animate from a template bound property (or change from one color to another in a template). Triggers use specific a specific property’s values (not the template).
Stay away from changing the existing triggers unless you are just changing color brushes.
Don’t rename or modify any element whose name starts with "PART_", they are referred to from the code that makes up the control. It breaks things.
Don’t think about removing helper elements, such as a Track in a SimpleScrollBar. These elements must be present to let the control function.
Don’t change/reset bindings in the Properties panel. They will have a yellow highlight around the property. Instead go in and edit the template for it.
If the template includes a presenter element like a ContentPresenter or ItemsPresenter make sure you keep that element in the template. Presenters display content that is defined in the control (where the template has been applied.