Reputation: 50712
Say I have a Grid, with a lot of cells on it, and I bind background of this cell to some property of my data class in a style (actually data class property is type of Color
, but this is not an issue, because we can use a converter to convert it to a Brush
),
Now when some condition in my data class is true I want the background to be red, and if not, I want it to be the default value, data may change, so condition may become true and false, and I should fill Background red or default
I know about Binding.DoNothing
and DependencyProperty.UnsetValue
both are not case, I tried also Cell.BackgroundProperty.DefaultValue
but it is null.
So Is there any value, that I can return from my bound data property, to force the dependency property to reset its value?
Thanks!
Upvotes: 0
Views: 470
Reputation: 184506
If you only have a boolean property that is quite convenient as you can use a DataTrigger
and just bind the value if the property is true
, that way the property is not always bound.
<Style.Triggers>
<DataTrigger Binding="{Binding MyCondition}" Value="True">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
If you only have the decision between default and red you do not even need the additional property or any binding at all.
(Resetting values is not possible in a binding to my knowledge)
Upvotes: 1