我对WPF中MVVM概念的解释(与演示者有关)(My interpretation of the MVVM

编程入门 行业动态 更新时间:2024-10-25 10:21:03
我对WPF中MVVM概念的解释(与演示者有关)(My interpretation of the MVVM-concept in WPF (In relation to presenters))

这是对MVVM概念的正确解释吗?

DataTemplates - >查看 DependencyObject(Controls,ListView等) - > ViewModel DataContext - > Model

如果我要创建自己的ViewModel,它将取代实际的控件并需要显式模板?

ViewModel中的“模型”一词不是对实际模型的反应(例如在DomainModel中)?

对于模型我也添加了Presenters,我将其视为实用程序类,以提升和公开属性等视图。 你能说ViewModel是一个自上而下的表示(一个视图的模型),而一个Presenter更像是一个ModelView,一个自下而上的表示(一个模型的视图)?

在这种情况下,我将不得不修改上述内容:

... DataContext - > Presenter 演示者 - >模型

我通常不会从DependencyObject派生来创建我的自定义表示包装器,但只是创建我的自定义通用视图模型,如控件而不是我的模型的视图?

Is this a correct interpretation of the MVVM-concept?

DataTemplates -> View DependencyObject (Controls, ListView etc) -> ViewModel DataContext -> Model

If I were to create my own ViewModel, it would replace the actual controls and need explicit templating?

The word 'Model' in ViewModel is not reffering to the actual Model (such as in DomainModel)?

To the model I add Presenters as well, which I see as utility-classes to elevate and expose properties etc to the view. Can you say that a ViewModel is a top-down representation (a model of a view) and that a Presenter is more of a ModelView, a bottom-up representation (a view of a model)?

In that case I would have to modify the above to this:

... DataContext -> Presenter Presenter -> Model

And I wouldn't generally derive from DependencyObject to create my custom presentation-wrappers, but only to create my custom generic models of views such as controls rather then views of my model?

最满意答案

通常MVVM意味着这样解释:

查看 - >控件,DataTemplates等 模型 - >您的实际数据模型(数据库,或其他) ViewModel - >公开View可用于DataBinding的属性和命令

这意味着,View将ViewModel作为DataContext,ViewModel的属性反映了Model的数据,ViewModel的Commands在Model上运行。 在简单的情况下,Model和ViewModel有时是相同的。

可在此处找到概述: http : //blogs.msdn.com/b/johngossman/archive/2005/10/08/478683.aspx 如果您正在寻找它,您还可以找到构建MVVM应用程序的相关示例。

Usually MVVM is meant to be interpreted this way:

View -> Controls, DataTemplates etc. Model -> Your actual data model (database, or whatever) ViewModel -> Exposes properties and commands that the View can use for DataBinding

That means, your View has the ViewModel as a DataContext, the ViewModel's properties reflect the Model's data, and the ViewModel's Commands operate on the Model. In simple cases, Model and ViewModel are sometimes the same.

An overview can be found here: http://blogs.msdn.com/b/johngossman/archive/2005/10/08/478683.aspx You can also find quite a few examples on building an MVVM Application if you look for it.

更多推荐

本文发布于:2023-07-22 18:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222300.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我对   演示   概念   MVVM   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!