I've removed my previous answer since using a template selector is a much better way of doing this.
first I create a DataTemplateSelector class that can be used to switch between DataTemplates based on a binding, note the 2 properties that take in references to the styles that will be applied, I could have used find resource here but I think this is cleaner and doesn't require view designers to stick to hard coded template keys.
public class IsWashedStyleSelector : DataTemplateSelector
{
public DataTemplate TrueStyle { get; set; }
public DataTemplate FalseStyle { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
TestClass targetItem = item as TestClass;
if (targetItem != null)
{
return targetItem.IsWashed ? TrueStyle : FalseStyle;
}
return base.SelectTemplate(item, container);
}
}
Now to use this template selector I have to define 2 data templates and also instance the selector in xaml resources.
<DataTemplate x:Key="styleIsWashedTrue">
<Button>It's true</Button>
</DataTemplate>
<DataTemplate x:Key="styleIsWashedFalse">
<Label>is false</Label>
</DataTemplate>
<local:IsWashedStyleSelector x:Key="isWashedStyleSelector" TrueStyle="{StaticResource styleIsWashedTrue}" FalseStyle="{StaticResource styleIsWashedFalse}"/>
Finally the selector can be used in a DataGridTemplateColumn like so.
<DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridCheckBoxColumn Binding="{Binding IsWashed}"/>
<DataGridTextColumn Binding="{Binding Text}"/>
<DataGridTemplateColumn CellTemplateSelector="{StaticResource isWashedStyleSelector}"/>
</DataGrid.Columns>
</DataGrid>