不实现IValueConvert.ConvertBack的最佳实践 [英] Best practice when not implementing IValueConvert.ConvertBack

查看:133
本文介绍了不实现IValueConvert.ConvertBack的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道在实现没有有意义的ConvertBack实现(或仅用作OneWay的实现)的IValueConverter时,人们认为最佳实践是什么?

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)?

它应该抛出(在那种情况下是什么异常),返回null或返回一些默认值。

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

有什么想法?

推荐答案

IValueConverter.ConvertBack 建议返回 DependencyProperty.UnsetValue


数据绑定引擎未捕获
异常由用户提供的
转换器抛出的结果。由ConvertBack
方法引发的任何异常
,或由
ConvertBack方法调用的方法引发的任何未捕获的异常
,都将
视为运行-时间错误。通过返回
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.

这篇关于不实现IValueConvert.ConvertBack的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆