wpf 我的应用程序中使用 MVVM 设计模式的控制器是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16443662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are my controller in my application with a MVVM design pattern
提问by user2236165
I have developed a WPF-application. I have a mainwindow which inherit from Window, a tabcontrol and many tabitems in this tabcontrol which inherit from UserControl. Every tabitem has its own cs-file, where I code in C# all the businesslogic, and a XAML-file where the development of the UI is done. I also have a SQL Server with a database which i connect to trough LINQ.
我开发了一个 WPF 应用程序。我有一个继承自 Window 的主窗口、一个 tabcontrol 以及继承自 UserControl 的这个 tabcontrol 中的许多 tabitems。每个 tabitem 都有自己的 cs 文件,我在其中用 C# 编写所有业务逻辑,还有一个 XAML 文件,用于完成 UI 的开发。我还有一个带有数据库的 SQL Server,我通过 LINQ 连接到该数据库。
So i have to write about my choice of which controller i use in my application. This is where i get confused, since i havent manually programmed a controller and i thought the ViewModel would behave like a controller in my case. Could this be correct? Can the ViewModel behave like a controller?
所以我必须写下我选择在我的应用程序中使用哪个控制器。这是我感到困惑的地方,因为我还没有手动编程控制器,而且我认为 ViewModel 在我的情况下会像控制器一样运行。这可能是正确的吗?ViewModel 可以像控制器一样工作吗?
回答by Konstantinos Bakopanos
A controllercan send commands to its associated view to change the view's presentation of the model (e.g., by scrolling through a document). It can also send commands to the model to update the model's state (e.g., editing a document). Model_View_Controller
甲控制器可将命令发送到其相关联的视图改变视图的模型的呈现(例如,通过经由一个文档滚动)。它还可以向模型发送命令以更新模型的状态(例如,编辑文档)。模型_视图_控制器
The viewmodelis a “model of the view” meaning it is an abstraction of the view that also serves in mediating between the view and the model which is the target of the view data bindings. It could be seen as a specialized aspect of what would be a controller (in the MVC pattern) that acts as a converter that changes model information into view information and passes commands from the view into the model. The view model exposes public properties, commands, and abstractions. Model_View_ViewModel
的视图模型是一个表示它是兼作在视图中,这是视图数据绑定的目标的模型之间进行调解的视图的抽象“的视图模式”。它可以被看作是控制器(在 MVC 模式中)的一个专门方面,它充当转换器,将模型信息更改为视图信息并将命令从视图传递到模型中。视图模型公开公共属性、命令和抽象。模型_视图_视图模型
The introduction of MVVMC(MVC + MVVM) is nessesary in cases you would like to drive many similar pairs of View-ViewModel (use cases). You can then introduce controllers. Model_View_ViewModel_Controller
如果您想驱动许多相似的 View-ViewModel 对(用例),则必须引入MVVMC(MVC + MVVM)。然后,您可以引入控制器。模型_视图_视图模型_控制器
回答by Michael Gunter
In the simplest case, have the ViewModel implement the "controller" logic. For large applications, I sometimes use an MVVMC pattern which uses a separate controller class. There has been a lot of recent support on the blogosphere for using MVVMC over MVVM.
在最简单的情况下,让 ViewModel 实现“控制器”逻辑。对于大型应用程序,我有时会使用 MVVMC 模式,该模式使用单独的控制器类。最近在博客圈上有很多人支持在 MVVM 上使用 MVVMC。
MVVM is dead, long live MVVMC!
MVMMC – MVVM grows a Controller

