Building Windows 8 MVVM XAML Apps

This course covers how to use the Model-View-ViewModel (MVVM) pattern to build Windows Store XAML applications for Windows 8 and WinRT.
Course info
Rating
(321)
Level
Intermediate
Updated
Nov 20, 2012
Duration
5h 16m
Table of contents
Course Introduction
Windows 8 MVVM Fundamentals
Getting Started with MVVM
Structuring an App with MVVM
MVVM Support - Behaviors and Repository
Dynamic MVVM Structuring
Windows Store Application Navigation with MVVM
MVVM Maintainability
MVVM Toolkits
Description
Course info
Rating
(321)
Level
Intermediate
Updated
Nov 20, 2012
Duration
5h 16m
Description

Building Windows 8 Modern UI-styled applications presents a whole new arena for building applications. However, patterns that have evolved for building clients with other XAML platforms (WPF, Silverlight, and Windows Phone) apply equally to building Windows 8 XAML clients. The Model-View-ViewModel (MVVM) pattern has become the de-facto standard for building loosely coupled, maintainable, testable, pattern-based XAML client applications. This course teaches you the key concepts and application of the MVVM pattern using the WinRT platform to build Windows Store XAML Apps for Windows 8.

About the author
About the author

Brian Noyes is CTO and Architect at Solliance, an expert technology solutions development company. Brian is a Microsoft Regional Director and MVP, and specializes in rich client technologies including XAML and HTML 5, as well as building the services that back them with WCF and ASP.NET Web API.

More from the author
WPF Productivity Playbook
Intermediate
2h 57m
22 Aug 2016
More courses by Brian Noyes
Section Introduction Transcripts
Section Introduction Transcripts

Windows 8 MVVM Fundamentals
In this module, I'll cover some of the fundamental concepts of MVVM in Windows 8 you need to understand before getting started with the MVVM pattern. I'll cover things like what kinds of applications you can create, some of the terminology around Windows 8 applications and some of the background on the MVVM pattern itself. First, I'll start with the different types of applications you can build with Windows 8, desktop and Window Store Applications. We'll get into the details of what it means to be a Windows Store Application, then we'll talk about Modern UI Style, also known as Metro Style in the past and I'll clarify what that means and what some of the key aspects of it are. Then we'll get visual and make sure it's very clear what all these things mean by demonstrating these in the Windows 8 environment. Next, I'll cover the WinRT platform itself which is what you'll use to build Windows Store Applications and I'll make sure it's clear to you how it relates to previous client application technologies and what the different technologies are that you can use to build WinRT applications. Then we'll get into MVVM itself and talk about how it relates to other XAML technologies and what some of the genesis of where it came from is. We'll talk about the overall design goals of MVVM to make sure you understand why you would bother using this pattern in the first place. And then I'll finish off by talking about some of the heritage of where MVVM came from and how it relates to other patterns such as MVC and MVP.

MVVM Support - Behaviors and Repository
In this module, I'll talk about a couple of important pieces of infrastructure support for doing the MVVM Pattern. Now, neither of these are required to do MVVM, but they help clean up some of the places that you'll need to put code and separate responsibilities a little bit more. Specifically, I'll talk about behaviors in two different forms, Attached and WinRtBehaviors, and I'll talk about the repository pattern and how they implement those. First, I'll talk about Attached and WinRtBehaviors. Attached behaviors are based on attached properties and let you hook up to a XAML element and add functionality to it. And conceptually, WinRtBehaviors are similar but they're based on some structure, a little bit different way of structuring the code that is based on the Blend SDK that's available for WPF, Silverlight, and Windows Phone, but is not yet available for WinRT. So, community members stepped up to the plate and defined some basic classes to let us follow that structure of Blend behaviors and WinRT today. So, I'll demo how to define and use an Attached behavior. And I'll demo how to define and use a WinRtBehavior. Then, I'll talk about the repository pattern. And this is another layer of separation you can put on the client's side in your application to make it so your view models don't have to know exactly what to do about persistence. So, I'll demonstrate a simple repository, how you implement it, and how the view models consume it.

Dynamic MVVM Structuring
In this module, I'll talk about dynamically-associating Views and ViewModels. All the examples we've seen so far have static wiring of a ViewModel from the View itself. In this module, we'll see how to do dynamic wiring of the View and ViewModel in both directions, View-First and ViewModel-First. We'll talk about hierarchical ViewModels, DataTemplates as a means of rendering a View for a ViewModel and also ViewModelLocators. First, I'll talk about some of the underlying concepts of why you might want to dynamically associate Views and ViewModels and how it's different from what we've talked about before and I'll cover what the supporting technologies are in terms of DataTemplates and ViewModelLocators. And we'll get specifically into DataTemplates and DataTemplateSelectors which are a capability of the platform associated with data binding. You need to understand how those work before you can understand how they support the MVVM pattern. Then, I'll demonstrate how to tie this stuff together where you'll have a hierarchy of ViewModels and you'll have DataTemplates associated with those ViewModels and you'll have a DataTemplateSelector that is used to tie them all together and dynamically render Views with our associated ViewModel hooked up at runtime. I'll do another demo that's similar but shows you that in the context of a Windows 8 specific container control called the FlipView which allows you to sequence between different child views and this will show you using that same dynamic content selection with the FlipView. Then I'll get into the concepts of ViewModelLocators which is a different way of going about dynamically-associating Views and ViewModels. It's a View-First type of approach where the View comes into being, but the View doesn't have to know about what its ViewModel is. The ViewModelLocator will select and associate a ViewModel with it. Finally, I'll demonstrate that concept and there's couple different ways you can go about implementing those and I'll show both of those ways within the demo.

MVVM Maintainability
In this module, I'm going to talk about two aspects that are important to the maintainability of your MVVM based application. One is leveraging design time support in Visual Studio 2012 and Microsoft Expression Blend. The other is unit testing in your ViewModels. Now this is not meant to be a comprehensive course on unit testing. I will talk about some of the fundamentals and demonstrate those but I encourage you to check out any number of very good courses in the Pluralsight library on unit testing with MSTest, Mocking with Moq and a number of others. If you just search on unit test in the Pluralsight library, you'll find a bunch of very elated courses. But I'll cover the basics here as it relates to unit testing functionality in your ViewModel. First I'm going to talk about design time data support and what that really means to your application and what it can do for you. And then I'll demonstrate it in the context of Visual Studio 2012. Next, I'll talk about MVVM and unit testing. General concepts and how they relate. I'll talk about unit test substitution also known as mocking because that's an important part of substituting dependencies that the ViewModel might have such as a repository lair or service calls. I'll cover several different mocking approaches and talk about which of those are actually available to you in Win RT at the current time. Also talk a little bit about the general concept of dependency injection and how it relates to mocking. Finally, I'll demonstrate how all this works in the context of a ViewModel and there are some functionality that we want in unit test. Show you how to put together those unit tests and also talk about some patterns that you may need to employ in your ViewModel to make it more testable.

MVVM Toolkits
In this final module, I want to get you familiar with a few MVVM Toolkits that are out there that can help you in implementing your applications. I'll talk briefly about the features and demonstrate both the MVVM Light Toolkit and Caliburn Micro. And at the end, I'll also talk about some Microsoft patterns and practices, toolkits and guidance that are available as well. I'll start with a brief overview of what I mean by a toolkit and the kinds of stuff that you can expect from them. Then I'll get into the MVVM Light Toolkit and talk briefly about the features that it offers. I'll demonstrate a simple application that's using MVVM Light, so you can see some of those in contrast them to what you've seen in the rest of the course. Then I'll talk about Caliburn Micro, which is sort of a competitor for MVVM Light in some ways but they actually supplement each other in other ways. I'll demonstrate a Hello World kind of application with Caliburn Micro and show you the MVVM constructs there, and some very unique aspects that Caliburn Micro has that other toolkits and approaches do not. Finally, I'll finish off with some coverage of Microsoft patterns and practices toolkits or guidance as they call it that can be used instead of or in addition to MVVM Light or Calibrun Micro.