Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:wpf:styles_and_triggers [2010/12/17 16:32]
smayr [iPad-style Switch (using CheckBox)]
swdev:dotnet:wpf:styles_and_triggers [2011/04/27 14:30] (current)
smayr
Line 41: Line 41:
 Source: [[http://www.microsoft.com/belux/msdn/nl/community/columns/gillcleeren/wpf_stylesandtriggers.mspx|Styles and Triggers in WPF]] 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:
 +<code xml>
 +<Style...>
 +  <Setter Property="Template">
 +    <Setter.Value>
 +       <ControlTemplate TargetType="{x:Type ListBox}">
 +           <Border 
 +               HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
 +               Background="{TemplateBinding Background}" 
 +               />
 +               ...
 +       </ControlTemplate>
 +    </Setter.Value>
 +  </Setter>
 +</Style>
 +</code>
 +
 +Restyle Datagrid's Checkbox column:
 +<code xml>
 +<UserControl.Resources>
 +    <DataTemplate x:Key="MyCheckBoxTemplate">
 +        <CheckBox Style="{StaticResource AnyResourceKeyInApplecation}"/>
 +    </DataTemplate>
 +</UserControl.Resources>
 +<DataGrid x:Name="dataGrid" />
 +</code>
 +
 +<code csharp>
 +this.dataGrid.Columns.Add(new DataGridTemplateColumn{
 +    CellTemplate=this.Resources["MyCheckBoxTemplate"] as DataTemplate});
 +
 +// OR this way:    
 +column2.ElementStyle = Application.Current.FindResource("MyCheckBoxStyle");
 +</code>
 == Triggers == == Triggers ==
  
Line 182: Line 218:
 </CheckBox> </CheckBox>
 </code> </code>
 +
 +== Resources ==
 +  * [[http://msdn.microsoft.com/en-us/library/ms745683.aspx|MSDN: Styling and Templating]]