MVVM绑定到Model或ViewModel? [英] MVVM binding to Model or ViewModel?

查看:153
本文介绍了MVVM绑定到Model或ViewModel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在读微软的Prism文档,它有一个对MVVM框架的冗长讨论。讨论模型的部分和讨论ViewModel的一节讨论了View绑定到每个中声明的属性。它是否正确?我读到的所有内容,直到这样才能使ViewModel看起来像是想要的绑定源,而Model更是业务逻辑。任何澄清将不胜感激。

I've been reading Microsoft's Prism Documentation and it has a lengthy discussion of the MVVM framework. Both the section discussing the Model and the one discussing the ViewModel talk about the View binding to the properties declared in each. Is this correct? Everything I read up until this made it seem like the ViewModel was the intended binding source, and the Model was more of the business logic. Any clarification would be appreciated.

推荐答案

几乎所有的时间你将绑定到ViewModels,这将包装模型和添加方便与您的UI有关的功能(直接不属于模型)。 有时不需要很多方便,你可能会直接绑定到模型(虽然我个人选择永远不会这样做)。

Almost all of the time you will be binding to ViewModels, which will wrap Models and add convenience functionality that has to do with your UI (and which would hardly belong to the Models directly). Sometimes not much convenience is required and you might end up binding to Models directly (although personally I choose to never do this).

文档在你提到的时候确实有点不清楚,但总而言之,你对这种情况的把握是现实的。

The documentation is indeed a bit unclear on this as you mention, but in a nutshell your grasp of the situation is spot on.

这篇关于MVVM绑定到Model或ViewModel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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