.Net 4.5:我应该使用 IDataErrorInfo 还是 INotifyDataErrorInfo? [英] .Net 4.5 : Should I use IDataErrorInfo or INotifyDataErrorInfo?

查看:27
本文介绍了.Net 4.5:我应该使用 IDataErrorInfo 还是 INotifyDataErrorInfo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经在我的 MVVM/WPF 应用程序中使用 IDataErrorInfo.现在 INotifyDataErrorInfo 在 .Net 4.5 中可用后,是替换 IDataErrorInfo 还是继续使用 IDataErrorInfo 的旧方式更好?

I used to use IDataErrorInfo in my MVVM/WPF applications. Now after INotifyDataErrorInfo is available in .Net 4.5 is it better to replace IDataErrorInfo or continue the old way using IDataErrorInfo?

推荐答案

INotifyDataErrorInfo 有许多改进(特别是,它支持每个对象/属性的多个动态变化的错误消息)这使它优于以前的界面.但最大的区别是它是异步的.您现在必须在错误状态发生变化时触发 ErrorsChanged 事件.

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 ErrorsChanged event whenever the error state changes.

如果您正在 .NET 4.5 中实现面向运行 Windows 8 的设备的应用程序,您应该强烈考虑使用新界面.异步式编程是此类应用程序的预期模型",尤其是当您包含 RT 设备时.在 IDataErrorInfo 上实现 INotifyDataErrorInfo 并没有那么复杂,所以实际上并没有什么缺点.

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 INotifyDataErrorInfo over IDataErrorInfo, so there's not really a downside.

不过,这并不意味着您应该改造所有现有的应用程序;同样,这取决于您的目标.如果您尝试将现有应用程序升级为与 RT 兼容,您可能应该更换新的错误处理代码.否则,无需更改有效的方法.

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.

这篇关于.Net 4.5:我应该使用 IDataErrorInfo 还是 INotifyDataErrorInfo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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