wpf - 不实现 IValueConvert.ConvertBack 时的最佳实践

标签 wpf data-binding

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

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

想法?

最佳答案

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

关于wpf - 不实现 IValueConvert.ConvertBack 时的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/265515/

相关文章:

c# - 将复选框/单选按钮 boolean 值保存到全局变量

c# - 使用文本框过滤列表框项目

c# - 我如何使用 WPF 为 Google Chrome 之类的窗口设置主题?

WPF 用户控件数据绑定(bind)不起作用

spring - 不使用 spring taglib 的数据绑定(bind)

wpf - 将 adorner 属性绑定(bind)到 viewmodel 属性

wpf - 将 3D 对象数据移动到单独的 XAML 文件中

c# - WPF如何优化布局/渲染周期?

data-binding - ngFor 内部的 Angular2 ngModel

.net - 以编程方式强制 TextBox 值从 V 到 VM?