wpf mvvm混乱 [英] wpf mvvm confusion

查看:94
本文介绍了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...

或者请用示例编写somethng来清除mvvm ...以及为什么mvc或mvp对于wpf应用程序来说是地狱??

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

推荐答案

该模型不实现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包含数据转换器 将模型类型转换为视图 类型,并且包含Commands 视图可用于与 模型.

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天全站免登陆