问题描述
如果我的域对象实现了 IDataErrorInfo,并且我使用的是 M-V-VM,我如何通过 ViewModel 将错误传播到 View?如果我直接绑定到模型,我会在绑定上将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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!