I have a poco class in my domain model:
public class Slot
{
bool HasPlayed { get; set; }
}
And I am displaying it in a listbox item template.
<Border Background="...">
<CheckBox IsChecked="{Binding Path=HasPlayed, Mode=TwoWay}" />
</Border>
But what I want to do is when the HasPlayed is true, the background color of the border turns red, and when false it’s green. These brushes are in a resource dictionary.
I could add a Brush to the domain model, but that defeats the seperation of concerns. I also am NOT going to use the checkbox in the future, this is just a mock up UI.
I’ve tried a IValueConverter, but it doesn’t change when the property changes. The model does implement INotifyPropertyChanged.
How would you change the color when the property changes?
You could use a DataTrigger to trigger the action:
http://en.csharp-online.net/WPF_Styles_and_Control_Templates%E2%80%94Data_Triggers