wpf mvvm 混乱 [英] wpf mvvm confusion

查看:28
本文介绍了wpf mvvm 混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我对 mvvm 的理解.

as per my understanding about mvvm is.

有一个模型(也实现 inotify 的实体类...)、视图(xaml 代码)和一些类作为 vm(通常继承 icommand 的控制器)让我们在特定的情况下生成要生成的事件/命令事件...

there is a model (entity class that also implement inotify...), view (xaml code) and some class as vm (kind of controller which normally inherit icommand) to let us make events/commands to be generated on specific event...

我只是想知道viewmodel类和xaml类背后的代码之间的区别......为什么我们不简单地考虑和增强背后的代码......

m just wondering about difference between viewmodel class and xaml's code behind class... why don't we simply consider and enhance code behind...

在我看来没有足够的理由来证明这一点......

no considerable reason is in my mind to justify this...

或者用例子写一些东西来清除 mvvm ......为什么 mvc 或 mvp 对 wpf 应用程序来说是地狱????

or kindly write somethng with example to clear mvvm... and why mvc or mvp is hell for wpf app????

推荐答案

Model 没有实现 INotifyPropertyChanged,ViewModel 实现了.实际的 WPF 视图数据绑定到 ViewModel.现在有很多在线文档.

The Model does not implement INotifyPropertyChanged, the ViewModel does. The actual WPF view data-binds to the ViewModel. There is now a lot of documentation online for this.

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

MVVM 与 Fowler 的相同演示模型,因为两者模式的特点是抽象视图,其中包含视图的状态和行为.

MVVM is identical to Fowler's Presentation Model, in that both patterns feature an abstraction of a View, which contains a View's state and behavior.

http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx

然而在实践中,只有一小部分应用程序 UI 的子集可以是数据直接绑定到模型,特别是如果模型是预先存在的类或数据模式应用程序开发人员没有控制.该模型很有可能有一个不能是的数据类型直接映射到控件.用户界面可能想要执行复杂的操作必须在代码中实现在我们严格的情况下没有意义视图的定义但是太特定于包含在模型中(或者没有附带预先存在的模型).最后我们需要一个地方放置视图状态,例如选择或模式.ViewModel 负责对于这些任务.该术语意味着视图模型",可以认为作为视图的抽象,但它还提供专业的视图可以用于的模型数据绑定.在后一个角色中ViewModel 包含数据转换器将模型类型转换为视图类型,它包含命令视图可以用来与模型.

In practice however, only a small subset of application UI can be data bound directly to the Model, especially if the Model is a pre-existing class or data schema over which the application developer has no control. The Model is very likely to have a data types that cannot be mapped directly to controls. The UI may want to perform complex operations that must be implemented in code which doesn't make sense in our strict definition of the View but are too specific to be included in the Model (or didn't come with the pre-existing model). Finally we need a place to put view state such as selection or modes. The ViewModel is responsible for these tasks. The term means "Model of a View", and can be thought of as abstraction of the view, but it also provides a specialization of the Model that the View can use for data-binding. In this latter role the ViewModel contains data-transformers that convert Model types into View types, and it contains Commands the View can use to interact with the Model.

MVVM 与 WPF 相关联,因为当 WPF 的数据绑定机制与此模式结合时,可测试的 GUI 变得轻而易举.

MVVM is associated with WPF because WPF's data binding mechanism when combined with this pattern makes testable GUIs a breeze.

这篇关于wpf mvvm 混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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