Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice when not implementing IValueConvert.ConvertBack

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?

like image 390
soren.enemaerke Avatar asked Nov 05 '08 15:11

soren.enemaerke


1 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.

like image 186
Todd White Avatar answered Oct 09 '22 20:10

Todd White