在M-V-VM中使用IDataErrorInfo [英] Using IDataErrorInfo in M-V-VM

查看:72
本文介绍了在M-V-VM中使用IDataErrorInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的域对象实现了IDataErrorInfo,并且我正在使用M-V-VM,如何将错误通过ViewModel传播到视图中?如果我直接绑定到模型,则在绑定时将"ValidateOnExceptons"和"ValidateOnErrors"属性设置为true.但是我的ViewModel没有实现IDataErrorInfo.只有我的模特.我该怎么办?

If my domain objects implement IDataErrorInfo, and I am using M-V-VM, how do I propagate errors through the ViewModel into the View? If i was binding directly to the model, I would set the "ValidateOnExceptons" and "ValidateOnErrors" properties to true on my binding. But my ViewModel doesn't implement IDataErrorInfo. Only my model. What do I do?

说明 我正在处理在域对象中实现IDataErrorInfo的现有代码库.我不能只在我的视图模型中实现IDataErrorInfo.

Clarification I am dealing with an existing codebase that implements IDataErrorInfo in the domain objects. I can't just implement IDataErrorInfo in the my view model.

推荐答案

您还可以在VM中实现IDataErrorInfo,并将对VM的调用路由到相应的域对象.我认为这是不将域对象直接暴露给视图的唯一方法.

You can implement IDataErrorInfo additionally in your VM and route the calls to the VM to your corresponding domain objects. I think this is the only way without exposing domain objects directly to the view.

这篇关于在M-V-VM中使用IDataErrorInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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