wpf .Net 4.5:我应该使用 IDataErrorInfo 还是 INotifyDataErrorInfo?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19402840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.Net 4.5 : Should I use IDataErrorInfo or INotifyDataErrorInfo?
提问by Hussein
I used to use IDataErrorInfoin my MVVM/WPF applications. Now after INotifyDataErrorInfois available in .Net 4.5 is it better to replace IDataErrorInfoor continue the old way using IDataErrorInfo?
我曾经IDataErrorInfo在我的 MVVM/WPF 应用程序中使用。现在INotifyDataErrorInfo在 .Net 4.5 中可用之后是替换IDataErrorInfo还是继续使用旧方式更好IDataErrorInfo?
回答by Michael Edenfield
There are a number of improvements in INotifyDataErrorInfo(in particular, it's support for multiple, dynamically changing error messages per object/property) that make it superior to the previous interface. But the biggest difference is that it's asynchronous. You now have to fire the ErrorsChangedevent whenever the error state changes.
有许多改进INotifyDataErrorInfo(特别是,它支持每个对象/属性的多个动态更改的错误消息),使其优于以前的界面。但最大的区别是它是异步的。您现在必须ErrorsChanged在错误状态发生变化时触发该事件。
If you are implementing an application in .NET 4.5 that targets devices running Windows 8, you should strongly consider using the new interface. Asynchronous-style programming is the "intended model" for such applications, particularly if you include RT-devices. It's not that much more complex to implement INotifyDataErrorInfoover IDataErrorInfo, so there's not really a downside.
如果您正在 .NET 4.5 中实现面向运行 Windows 8 的设备的应用程序,则应强烈考虑使用新界面。异步式编程是此类应用程序的“预期模型”,尤其是当您包含 RT 设备时。实现INotifyDataErrorInfooverIDataErrorInfo并没有那么复杂,所以并没有真正的缺点。
That doesn't mean you should go retrofit all your existing applications, though; again, it depends on your target. If you're trying to upgrade an existing application to be RT-compatible, you should probably swap in the new error handling code. Otherwise, no need to change what works.
不过,这并不意味着您应该改造所有现有的应用程序。同样,这取决于您的目标。如果您尝试将现有应用程序升级为与 RT 兼容,您可能应该更换新的错误处理代码。否则,无需更改有效的方法。

