Deep Dive MVVM samples #mix11 #deepdivemvvm

Here is the sample code I demoed in my MIX11 session “Deep Dive MVVM”. Please download the Zip file, and then unblock it in Windows Explorer by right-clicking it, and then selecting Properties. If you see an “Unblock” button, please click it. You can then extract the content of the Zip file on your hard drive.

The slides are also available for download.

Last year’s session

To fully understand this session, an understanding of what MVVM is should be available. I recommend the following links:

This year’s session

The video of Deep Dive MVVM is already available for download (awesome job, MIX team). Go to the MIX website to download it in various formats, or stream it.

Prerequisites

To execute the samples, you should have Visual Studio 2010 as well as the Windows Phone 7 tools installed.

Update: Getting the samples to run

In order to run the JsonDemo sample, you need to run the web application first because the Facebook service simulation is local. The easiest way is to right click on JsonDemo.SL4TestPage.html and select “View in Browser” from the context menu. This will start the development web server in Visual Studio. Then, you can run the WP7 application in the emulator.

Snippets

For your convenience, I added the snippets of code that I was dragging/dropping from the Toolbox during the session. The file “snippets.txt” is included inside the ZIP file.

00 JsonDemo – Start

This is the start state, which will compile and run fine, but without the added functionality we built in during the session.

01 JsonDemo - After wiring up

This is the state of the application after the first demo, where all the objects are wired up and connected, and the message is sent from the MasterViewModel to the DetailsViewModel. We also added the IsOlderThanMeIndicatorVisibility property and connected it to the corresponding Rectangle in the DataTemplate (in the MasterView).

02 JsonDemo – Behaviors

This is the state after adding the “please wait” animation, the states and connecting the MasterViewModel’s IsBusy property to the GoToStateAction and ControlStoryboardAction instances through the DataTrigger. In Windows Phone 7, we added some code behind to replicate the functionality.

03 JsonDemo - WP7 DialogService

In this section we added a view service, the IDialogService, to the WP7 application and implemented it to display a custom message box. In SL4, the functionality is also available although no custom message box was made, so the fallback MessageBox is used instead.

04 NavigationDemo

This section introduces another view service, the INavigationService with one implementation in Silverlight 4 and one for Windows Phone 7.

05 JsonDemo - Unit test

In this last section, we add unit tests (with mock, well precisely with stubs!) to the Silverlight 4 and to the Windows Phone 7 applications. This is the final state of the demo.

I hope that this session was helpful, and that it will help you build awesome MVVM applications!

Happy coding,

Laurent

 

Print | posted on Wednesday, April 13, 2011 3:04 PM

Feedback

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Valeriu Caraulean at 4/13/2011 4:53 PM Gravatar
Any idea if/when/where video recording of your session will be available?

And, if you intended to post snippets themselves, they aren't showing in my browsers...

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Jerome at 4/13/2011 9:38 PM Gravatar
The video is available at :
http://channel9.msdn.com/Events/MIX/MIX11/OPN03

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Valeriu Caraulean at 4/14/2011 12:21 AM Gravatar
@Jerome, thank you! watching it now...

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Mikhail Orlov at 5/4/2011 9:00 PM Gravatar
How to actually run these and get some working results?

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Laurent Bugnion at 5/9/2011 5:30 PM Gravatar
Hi Mikhail,

What did you try and what results did you get?

Laurent

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Sreeram Gurram at 5/12/2011 8:24 PM Gravatar
IDialogService pattern to display custom messages is an excellent idea.
I am planning to use this in my WPF app to replace Messenger's DialogMessage implementation.

Great work Laurent.

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Prakash at 6/14/2011 10:14 AM Gravatar
Kewl, IDialogService pattern is neat, next needed is a simple IAnimationService. Laurent, when you throwing that one in the mix. lol

PS

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Peter Cabus at 8/7/2011 7:51 AM Gravatar
Great video! Even the advanced concepts are easy to understand. I also appreciate your presentation style. Nice work Laurent.

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Rakesh at 8/20/2011 5:40 PM Gravatar
Nice Work

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Berthier Lemieux at 1/16/2012 9:27 PM Gravatar
Bonjour Laurent,

Thanks for that presentation, it's solid stuff I was really looking after.
I tried the source code of the NavigationDemo on my environment, WP7.1 + VMMV 4 beta 1, and it really doesn't work. As soon as I click on one of the news item, I get an "item not found".
I debugged the thing a bit, and as far as I could tell, you're using the wrong test in the code behind of NewsItemPage, in the OnNavigatedTo method.

You're checking if there is an instance of viewmodel already available :
if (!SimpleIoc.Default.Contains<NewsItemViewModel>(itemUrl))

But since it's the first time I click on that newsItem, the instance hasn't been created, the test fails and therefore I get a "item not found".

I get the code to work if I change the check above with:
if (!SimpleIoc.Default.IsRegistered<NewsItemViewModel>(itemUrl))

The desired viewmodel has been registered, so the test pass through, and the SimpleIoc will create the instance when the code will request the instance, a few lines down.

I'm still very new to VMMV Light, did I got it right?

# re: Deep Dive MVVM samples #mix11 #deepdivemvvm

left by Berthier Lemieux at 1/21/2012 7:29 PM Gravatar
I created a zip file with WP7.1 support, for those who would like to play with the deep dive sample code on a Mango environment : http://pankakeit.com/theBlog/?p=46
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: