是什么让MVVM特别适合WPF?适合、MVVM、WPF

2023-09-03 10:21:45 作者:underneath(云影)

借助模型 - 视图 - 视图模型是与WPF很受欢迎, Silverlight的。我一直在使用这对我最近的项目,是一个非常大的风扇。

The Model-View-ViewModel is very popular with WPF and Silverlight. I've been using this for my most recent projects, and am a very large fan.

据我所知,它是 MVP 的细化。不过,我想知道到底是什么的WPF(和Silverlight)的独特的特性使得MVVM工作,和prevent(或者至少作出困难的)使用其他框架或技术工作的这种模式。

I understand that it's a refinement of MVP. However, I am wondering exactly what unique characteristics of WPF (and Silverlight) allow MVVM to work, and prevent (or at least make difficult) this pattern from working using other frameworks or technologies.

我知道MVVM对强大的数据在WPF绑定技术很强的依赖性。这是一个特点,许多文章和博客似乎提到作为是关键WPF提供查看从视图模型的强分离的手段。然而,数据绑定存在于多种形式在其他的UI框架。甚至有一些项目,如桁架提供WPF式的数据绑定到POCO在.NET。

I know MVVM has a strong dependency on the powerful data binding technology within WPF. This is the one feature which many articles and blogs seem to mention as being the key to WPF providing the means of the strong separation of View from ViewModel. However, data binding exists in many forms in other UI frameworks. There are even projects like Truss that provide WPF-style databinding to POCO in .NET.

哪些功能,除了数据绑定,使WPF和Silverlight特别适合模型 - 视图 - 视图模型?

What features, other than data binding, make WPF and Silverlight uniquely suited to Model-View-ViewModel?

推荐答案

数据绑定,命令,控制模板和XAML。

DataBinding, commands, control templates and XAML.

如果没有其中之一,MVVM将是一个很大困难,甚至是不可能的。采取ASP.net例如,它具有ASPX部分(这是为了示例的相当于XAML),它具有数据绑定,但它不具有命令或控制模板,所以MVVM是不可能存在。在的WinForms,我们绑定,这是pretty的多,所以不可能任。

Without one of these, MVVM would be a lot harder, if not impossible. Take ASP.net for instance, it has the ASPX part (which for the sake of the example is equivalent to XAML), it has data binding, but it doesn't have commands or control templates, so MVVM is not possible there. In WinForms, we have databinding, and that's pretty much it, so not possible either.