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.
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.
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.
What features, other than data binding, make WPF and Silverlight uniquely suited to Model-View-ViewModel?
DataBinding, commands, control templates and XAML.
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.
In short: it's the data binding.
Per the Data Binding Overview from MSDN:
If the binding has the correct settings and the data provides the proper notifications, then, when the data changes its value, the elements that are bound to the data reflect changes automatically. Data binding can also mean that if an outer representation of the data in an element changes, then the underlying data can be automatically updated to reflect the change. For example, if the user edits the value in a TextBox element, the underlying data value is automatically updated to reflect that change.
If you set your XAML up correctly, you only have to interact with your user interface using the viewmodel. WPF takes care of updating the UI when the viewmodel changes, and updating the viewmodel when the UI changes (ex. user input).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With