问题描述
如果我的域对象实现了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.
ClarificationI 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!