I have created UserControl
that provides few dependency properties
. The value of one of them is int
. Now the user has provided the null
as value and an exception has been thrown:
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='<null>'
...
Which is a valid behaviour (by WPF I believe?). However I want to prepare my UserControl
for such incident. I mean, if binding provides invalid value I want to catch this and provide my default value, so no exceptin is thrown.
How to achieve this? I've tried with DependencyPropertyChangedCallback
, CoerceValueCallback
and ValidateValueCallback
callbacks but it seems none of them receive this value.