Better User and Developer Experiences – From Windows Forms to WPF with MVVM: Introduction
I feel that the confusion around choosing WPF really stems from a lack of understanding about WPF. Even people on my own team have been overwhelmed trying to understand how the different pieces of WPF fit together, and how to apply the new concepts introduced with WPF effectively. In order to address this, I’m going to break this down into a few simple pieces, and show the migration in terms of thought required to transition from being a good Windows Forms developer to an effective WPF developer.
Windows Presentation Foundation is huge. Do not doubt it. It is huge, both in terms of scope, but also in terms of the radically different approach it takes to developing user interfaces than other technologies. Don’t let the scope frighten you, however – it is very well thought out, and very usable, once you understand some of the basic concepts.
In addition to the huge scope of WPF, new design patterns have evolved to take advantage of the new features introduced by this framework. The most commonly referenced one, in terms of WPF, seems to be MVVM, or Model-View-ViewModel. The Model-View-ViewModel pattern was inspired by some of the features in WPF, and seems perfectly fit for WPF, so many developers advocate it (with good reason) for use with WPF.
Again, don’t let this frighten or discourage you… MVVM isn’t about making WPF more difficult, it’s about making WPF usable in a quick, efficient manner. Learning MVVM actually makes understanding WPF easier, not more difficult.
The issue here is that WPF is large, and the framework doesn’t force you into a single way of working. There are lots of ways to work with WPF, including doing nearly the exact thing you’re used to with Windows Forms! This is part of the power and flexibility of WPF, but also a trap to watch for and to avoid. MVVM helps guide and force you to take advantage of WPF’s new features effectively, insulating you from common pitfalls and mistakes.
For this series, I’m going to start by showing a simple Windows Forms application – an RSS Feed Reader, and demonstrate converting it to WPF. I’ll start with a strait conversion – and demonstrate how you can make WPF look and work exactly the same as you can with Windows Forms. I’ll then explain, in details, some of the new ways of thinking that are pervasive within WPF, and show how this should change your way of thinking about user interfaces.
In order to do this, we’ll work with four separate projects – which include three completely different versions of the same application. The goal here isn’t to use WPF to make the application “pretty” or “flashy”, rather, it’s to show how you can use WPF to make an application more developer friendly, including making it cleaner, more logical, easier to maintain, and more testable.