This project has moved. For the latest updates, please go here.

Issues with converters when value is DependencyObject.UnsetValue


Basically the converters fail with a cast exception when the value is DependencyObject.UnsetValue.

Basically this value could be passed as value when you are binding for example to a binding that cannot be properly resolved at a certain point in time but that does get resolved in the future.
I had this problem with the VisibilityToBooleanConverter for example.

It can be easily solved by adding this as first line for all converters (or at least where it makes sense, which is usually most of them):

if (value == DependencyObject.UnsetValue)
return DependencyObject.UnsetValue;

Also while at it, maybe add to VisibilityToBooleanConverter (and also to BooleanToVisibilityConverter) a property that lets you pick if a bool == false is Collapsed (default) or Hidden


xaviergonz wrote Jan 31, 2016 at 2:50 AM

Sorry where it says:
should be

xaviergonz wrote Jan 31, 2016 at 3:01 AM

And maybe for the sake of completeness add to each converter an attribute such as

[ValueConversion(typeof(Visibility), typeof(bool))]

I think the designer uses this info to know if the converter is proper for the type. but I'm not sure.