wpf mvvm混淆

标签 wpf model-view-controller mvvm mvp

据我对mvvm的理解是。

有一个模型(也实现inotify的实体类...), View (xaml代码)和一些类作为vm(通常继承icommand的 Controller ),让我们可以在特定的情况下生成事件/命令事件...

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

我认为没有充分的理由来证明这一点......

或者请写一些带有示例的内容来清除 mvvm...以及为什么 mvc 或 mvp 对于 wpf 应用程序来说是 hell ???

最佳答案

模型没有实现 INotifyPropertyChanged,而 ViewModel 则实现了。实际的 WPF View 数据绑定(bind)到 ViewModel。现在网上有很多这方面的文档。

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

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

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 的数据绑定(bind)机制与此模式相结合使可测试的 GUI 变得轻而易举。

关于wpf mvvm混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2198061/

相关文章:

java - 从服务器向所有客户端发送消息

wpf - 将两个命令绑定(bind)到一个按钮?

wpf - 有没有一种在 WPF 中绘制文本的快速方法

c# - 使用 Caliburn.Micro 将 View 模型中的图像加载到 View 中

azure - 如何修复 "Azure deployment with VS Code gives ' 您没有权限查看此目录或页面.'"

WPF 动态内容选项卡不适合替代 MDI 用户界面

c# - 自动生成可编译的 C# - 实现 INotifyPropertyChanged 的​​包装类

c# - 如何处理包含列表的 WPF 用户控件中的嵌套绑定(bind)?

c# - 如何为我的 UserControl 绑定(bind)不同的 DataContext?

asp.net-mvc - Mvc验证正则表达式只验证数字?