2

Any good sample WP7 application using MVVM model in the optimal way?

I'm creating my first WP7 app, and I'm using MVVM as far as I can tell, but I'm not sure I'm doing it the right way. I have one view model per page, instead of one main view model that branches to each page, I'm not sure which is the correct way to do, so I'm hoping there's a sample app out there that I can check out.

Thanks!

Edit: I'm also having another problem on saving the ViewModels in the application state, because I think they have to be serializable (haven't worked much into this), the thing is that when I start a task and come back to the app, the latter has already been deactivated by calling the former, so I have to serialize its state when deactivated and [re]serialize it when [re]activated. This is how I save the state when deactivated:

object[] viewModels = new object[3];

viewModels[0] = App.ViewModelPage1;
viewModels[1] = App.ViewModelPage2;
viewModels[2] = App.ViewModePage3;

PhoneApplicationService.Current.State.Add("LastState", viewModels);

Again, this is probably not efficient way to do it, so I'm hoping I can see a sample app that handles this well too.

Thanks!

1
  • I'm looking for something more complex than one page. What I'm really looking for is how each ViewModel comunicates with each other across pages, or even if that approach is the right one. In the links in the answers below, I saw repeated times that ViewModels are use per component rather than per page, so I'm not sure if I'm doing it right. I'm looking for an application like Flixter or IMDB that has several pages.
    – Carlo
    Commented Dec 7, 2010 at 22:28

5 Answers 5

1

Have you looked at using the MVVM Light toolkit?

Serialization best practices will vary based on the volume of data in the model, the number of models being used and whether it's necessary to always load all of the models.

1

You might want to check out Caliburn Micro. It is used to implement a number of user experience patterns but it supports WP7 and has sample code.

1

Here's some MVVM samples and guidance you can check out.

C#er : IMage: Model-View-ViewModel (MVVM) Explained

.NET by Example: Using MVVM Light to drive a Windows Phone 7 / Silverlight 4 map viewer

The simplest way to do design-time ViewModels with MVVM and Blend.

Also an overview here of MVVM frameworks you may find worth a look.

JAPF » Blog Archive » Discover and compare existing MVVM frameworks

Light weight seems to be good and MVVM Light is popular. Laurent demos MVVM in the Mix 10 video EX14 if you want to check that out too.

1
  • The JAPF comparison thing is great to discover the right framework for your needs. Very good.
    – SandRock
    Commented Dec 20, 2010 at 22:08
1

This months MSDN magazine has an article on creating a WP7 Sudoko app using MVVM.

http://msdn.microsoft.com/en-us/magazine/gg490347.aspx

HTH

0

Here is my article which describes the approach to build WP7 applications using advantages of separation of concerns: a framework for building of WP7 application

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.