C H A P T E R  13

The Model-View-ViewModel (MVVM) Design Pattern

Few topics surrounding Silverlight are so widely discussed as the Model-View-ViewModel (MVVM) design pattern. This pattern is used by many Silverlight, Windows Phone 7, and WPF developers, and even JavaScript libraries are starting to appear that enable HTML applications to make use of the pattern. The blogosphere is overflowing with posts on this topic, with so many differing and varied opinions on how it should be implemented that you might become a little overwhelmed. Adding to this confusion is the fact that the project templates in Visual Studio do not facilitate using the MVVM design pattern out of the box, and with no information on the amount of prerequisite Silverlight knowledge required to implement it effectively, many developers new to Silverlight shun the pattern until they become more experienced in the technology. However, there is general agreement in the development community that, regardless of how you implement the pattern, doing so is good practice. Developers who implement this pattern invariably say that their code is much better for it.

The MVVM design pattern has been mentioned frequently throughout this book, and some of the workshops in Chapters 6 and 7 even implemented it in its most primitive form. I've held off looking at the pattern in depth to avoid overloading you with too many new topics at the one time. However, now that we've covered the required data binding and XAML concepts that you will use when implementing the MVVM design pattern, this is the perfect time to learn about the MVVM and put those concepts into use implementing the design pattern.

images Note There's a learning curve when getting up to speed on the MVVM design pattern, but once you get the hang of it, you won't look back. Using the MVVM design pattern when you're used to writing code-behind only for views is somewhat like learning an object-oriented programming language when you're familiar only with structured programming languages. It will feel a bit weird at first as you work out where things go and how they communicate, but once you get your head around it, it will feel completely natural.

In this chapter, we'll start by looking at the theory behind the MVVM design pattern, then move onto the practical aspects of implementing it, and finally, look at the more complex areas of working within the pattern and how you can approach these problems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset