gpt4 book ai didi

wpf mvvm混淆

转载 作者:行者123 更新时间:2023-12-03 04:21:27 31 4
gpt4 key购买 nike

据我对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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com