== WPF Styles and Triggers ==
== Styles ==
Static resource style definition for a button:
Using the style:
Changing styles programmatically:
void Page_Load(object sender, RoutedEventArgs e) {
if (DateTime.Now.Month > 8 || DateTime.Now.Month < 3) {
Button1.Style = (Style)FindResource("WinterStyle");
} else {
Button1.Style = (Style)FindResource("SummerStyle");
}
}
Source: [[http://www.microsoft.com/belux/msdn/nl/community/columns/gillcleeren/wpf_stylesandtriggers.mspx|Styles and Triggers in WPF]]
=== Style Tricks ===
To use a parent property value, rather than a predefined value, use ''TemplateBinding'' + //PropertyName//. For example:
...
Restyle Datagrid's Checkbox column:
this.dataGrid.Columns.Add(new DataGridTemplateColumn{
CellTemplate=this.Resources["MyCheckBoxTemplate"] as DataTemplate});
// OR this way:
column2.ElementStyle = Application.Current.FindResource("MyCheckBoxStyle");
== Triggers ==
Example of a trigger that kicks in when MouseOver event occurs:
== TreeView with new Template ==
This ''TreeView'' template changes the expander (+/-) to new icons:
== iPad-style Switch (using CheckBox) ==
== Resources ==
* [[http://msdn.microsoft.com/en-us/library/ms745683.aspx|MSDN: Styling and Templating]]