Better User and Developer Experiences – From Windows Forms to WPF with MVVM
This series introduces the Model-View-ViewModel Pattern from the point of view of a Windows Forms developer. The goal is not to introduce WPF, but to demonstrate some of the new features within Windows Presentation Foundation, and show how they should force every WPF developer to re-think how they design their applications.
The Model-View-ViewModel pattern is introduced after a discussion of three of the main features in WPF which enable it’s usage. In order to illustrate this, three versions a single application were written:
- A Windows Forms application
- A WPF Version of the application, using the same style
- A WPF Version of the application, built using MVVM
This allows a detailed understanding of the reasons behind MVVM, as well as the technology that enables the pattern.
Series Outline
- Introduction
- The Model
- Our Application In Windows Forms
- Our Application In WPF
- Data Binding
- Commands
- Templating
- MVVM
- Conclusion
The source code for this series is posted on MSDN Code Gallery.
Note: Since the Code Gallery was removed, I have now attached the source code to this article. Â This is unchanged from the version posted with the original article.
From Windows Forms to WPF with MVVM
This talk illustrates how Windows Presentation Foundation can dramatically improve the experience of developers, not just designers. Two versions of a simple application will be demonstrated, one developed using Windows Forms, and one using the same approach in WPF. By showing the same application in both technologies, we will show how a short learning curve can be used to migrate development to WPF.
I’ll then discuss three new features of WPF: Data Binding, Templating, and Commanding. I’ll show how they enable a new application architecture, the Model-View-ViewModel pattern, and illustrate how rethinking our approach to design in terms of these three features allows for huge gains in flexibility, testability, and maintainability of our applications.
Finally, we’ll look at third version of our application, a rewrite of our previous application using the Model-View-ViewModel pattern.
This talk is approximately 1 hour and 15 minutes in length.
Presentation Material:
Slides:Â Windows Forms to WPF with MVVM
Better User and Developer Experiences – From Windows Forms to WPF with MVVM
This series introduces the Model-View-ViewModel Pattern from the point of view of a Windows Forms developer. The goal is not to introduce WPF, but to demonstrate some of the new features within Windows Presentation Foundation, and show how they should force every WPF developer to re-think how they design their applications.
The Model-View-ViewModel pattern is introduced after a discussion of three of the main features in WPF which enable it’s usage. In order to illustrate this, three versions a single application were written:
- A Windows Forms application
- A WPF Version of the application, using the same style
- A WPF Version of the application, built using MVVM
This allows a detailed understanding of the reasons behind MVVM, as well as the technology that enables the pattern.
Better User and Developer Experiences – From Windows Forms to WPF with MVVM: Conclusion
Windows Presentation Foundation provides us with new opportunities to build applications that are very flexible to design, easy to maintain, and clear to understand. By taking advantage of Data Binding, Commands, and Templating, we can rethink the way we build our applications, and design them using the Model-View-ViewModel Pattern.
Now that I’ve walked through how we do this, I will revisit our original RSS Feed Reader application, and show samples of how this changes the design and code in this simple application.
Better User and Developer Experiences – From Windows Forms to WPF with MVVM: Part 7, MVVM
I mentioned in the introduction that a new architectural pattern has emerged for Windows Presentation Foundation: Model-View-ViewModel. As I mentioned, MVVM can make developing applications in WPF efficient, quick, and highly maintainable. Now that I’ve covered some of the basic technological advances in WPF, mainly Data Binding, Commands, and Templating, it’s time to bring everything together, and demonstrate how this improves our jobs as developers.
Better User and Developer Experiences – From Windows Forms to WPF with MVVM: Part 6, Templating
In order to rethink how we architect and write client applications, there is one last important concept Windows Presentation Foundation introduces, beyond the excellent Data Binding and Commanding support I’ve already discussed. WPF adds an entire suite of features specifically related to Styling and Templating. This is often discussed in relation to improving the overall look, feel, and usability of applications written using WPF – the key to the new user experience (UX) WPF allows. However, the templating engine introduced with WPF has other side effects, which change the way we should design our software, not just change the way we stylize our software.
Better User and Developer Experiences – From Windows Forms to WPF with MVVM: Part 5, Commands
In the last article, I explained how Windows Presentation Foundation improves upon data handling via it’s excellent support for data binding. However, data is only part of the equation. In order to be a more effective framework, WPF also provides us a way to more effectively handle our application specific logic.
It does this by providing a unified model for separating the originator of an action from the effect produced by the action, via the Commanding infrastructure.
Better User and Developer Experiences – From Windows Forms to WPF with MVVM: Part 4, Data Binding
Now that I’ve demonstrated how WPF can be written in the same manner, using the same methods as prior windowing frameworks, it’s time to explain why this is a bad idea. To do this effectively, I’m going to discuss a few things that WPF introduces, and explain how they should change the way all of us approach building user interfaces. One thing I do want to mention – this series is not meant to be a full tutorial on WPF, rather an explanation of how to use features in WPF effectively.
The first new concept in WPF I’ll introduce is the new, more powerful, more flexible model for Data Binding.
Better User and Developer Experiences – From Windows Forms to WPF with MVVM: Part 3, Our Application in WPF
One common misconception I see when people start off with WPF is that they feel that it’s unapproachable, too complicated, and too unwieldy. There some fundamental shifts that every developer must deal with when the first switch to WPF, but they are actually fairly minor. You can program against the Windows Presentation Foundation API using the same basic techniques that you used in Windows Forms.
Better User and Developer Experiences – From Windows Forms to WPF with MVVM: Part 2, Our Application in Windows Forms
In order to fully understand how and why to migrate from Windows Forms to WPF, and from WPF to WPF using MVVM, we need to understand Windows Forms.
When Microsoft first developed and released .NET, they provided a very clean, simple API for creating Windows applications based upon existing technologies: Windows Forms. The Windows Forms programming model is an event based programming model. This matches very well with prior Microsoft technologies, such as ATL and MFC, since the core of Windows Forms wraps around controls defined in the Windows API.