If not, how can I achieve a similiar behaviour? I want to bind the Backgrond property of some control to a property of type Brush. I want to use the default background (which is resolved using a resource key) when that property is set to null.
Default implementation of TargetNullValue does not allow that. One of possible simple solutions can be implementing a Style with DataTrigger:
<Style TargetType="TextBlock">
<Setter Property="Background" Value="{Binding BrushProperty}" />
<Style.Triggers>
<DataTrigger Binding="{Binding BrushProperty}" Value="{x:Null}">
<Setter Property="Background" Value="{DynamicResource defaultBrush}" />
</DataTrigger>
</Style.Triggers>
</Style>
I used TextBlock type just as example, you can use the type you need there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With