Best practice when not implementing IValueConvert.ConvertBack

Viewed 7655

Just wondering what people think is the best practice when implementing an IValueConverter which does not have a meaningfull ConvertBack implementation (or one that is only to be used as OneWay)?

Should it throw (and in that case what exception), return null or return some default value.

Thoughts?

4 Answers

The documentation for IValueConverter.ConvertBack recommends returning DependencyProperty.UnsetValue.

The data binding engine does not catch exceptions that are thrown by a user-supplied converter. Any exception that is thrown by the ConvertBack method, or any uncaught exceptions that are thrown by methods that the ConvertBack method calls, are treated as run-time errors. Handle anticipated problems by returning DependencyProperty.UnsetValue.

According Microsoft, you should return DependencyProperty.UnsetValue

Related