WPF/XAML 与 MVC 范式:最基本的设计存在缺陷
在 MVC 中,模型可以有多个视图,在 WPF 中,XAML 代码隐藏模型仅限于 1 个 XAML(视图),WPF/XAML 从一开始就不存在 MVC 缺陷吗?
In MVC a model can have multiple views, in WPF a XAML code-behind model is tight to 1 single XAML (view) isn't WPF/XAML flawed from the start in respect to MVC ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议查看 MVVM 与 WPF 的配合使用。
您将 MVC 与 Windows 窗体与带有代码隐藏的 WPF 进行比较 - 即将架构模式与技术进行比较(不使用模式)。这是一个不公平的比较。
我在 从 Windows 窗体角度出发的 MVVM 可能有助于理解这一点。您会发现,使用 WPF 实现视图和视图模型的分离比 MVC 的控制器更清晰、更容易实现。它实际上允许更多解耦的架构,并且实现工作更少。
I recommend looking at MVVM for use with WPF.
You're comparing MVC with Windows Forms to WPF with code behind - which is comparing an architectural pattern to a technology (without using a pattern). This is an unfair comparison.
I wrote a series on MVVM starting from a Windows Forms perspective that may help with understanding this. You'll find that the separation of View and ViewModel possible with WPF is far cleaner and simpler to implement than the Controller of MVC. It actually allows even more decoupled architectures with less implementation work.
好问题!
在 MVC 中,您声明一个模型可以有多个视图,这是事实。但是,每个视图都有自己的控制器。
在 MVVM 中,一个模型可以有多个视图,在这种情况下,每个视图都可以有自己的视图模型。
然而,实际上,如果 ViewModel 没有任何与某个视图高度相关的概念,则完全有可能重用视图模型。事实上,我写了一篇关于跨平台 XAML 应用程序的文章,其中我在三个应用程序之间重用了代码,一个在 WP7 上,一个在 Silverlight 中,另一个在 WPF 中:
http://blogs.msdn.com/b/mikeormond/archive/2010/12/ 09/writing-cross-platform-xaml-applications.aspx
每个应用程序的视图都非常不同,但是我能够为所有三个应用程序重复使用模型和视图模型。
Good question!
In MVC you state that a model can have multiple views, which is true. However, each view would have its own controller.
In MVVM a model can have multiple views, and in this case each may have their own view model.
However, in practical terms, if a ViewModel does not have any concepts that are highly specific to a certain view, it is entirely possible to re-use view models. In fact, I wrote an article on cross-platform XAML applications where I re-used code between three apps, one on WP7, one in Silverlight, the other WPF:
http://blogs.msdn.com/b/mikeormond/archive/2010/12/09/writing-cross-platform-xaml-applications.aspx
The views for each were very different, however I was able to re-use both the models AND the view models for all three apps.
WPF/XAML 是一种技术,而 MVC 是设计模式,当技术不将您限制为特定模式并允许开发人员选择要使用的模式时,它是很好的。与编程语言相同,您可以使用任何设计模式。
您可以将 MVC、MVP、MVVM 或 YourMegaPattern 与 XAML\WPF 结合使用。技术应该高于模式,它的框架通常绑定到特定的模式。
例如,您可以采用ASP .NET技术,以及基于它的MVC框架。
WPF/XAML is a technology, and MVC is design pattern, it's good when technology is not limiting you to a specific pattern, and allows developer to choose what pattern to use. Same as programing languages allow's you to use any design pattern.
You can use MVC, MVP, MVVM, or YourMegaPattern with XAML\WPF. Technology should be above patterns, it's frameworks that are usually bound to a specific pattern.
For example you can take ASP .NET techology, and MVC framework based on it.