This project has moved. For the latest updates, please go here.

Passing parameters to a view model

Dec 22, 2012 at 10:08 AM

This is the first time I am working with MVVM Light and its View Model Locator. There is still some aspects I don't really get with the "view first" approach of MVVM Light. Before I was using Prism and Regions which allowed a "view model first" approach where you were instatiating a view model yourself.

What I don't get is how do you provide a parameter to a view model. For example I have a view with a collection of different objects and then I want to navigate to one of this object, but unfortunately I cannot pass the Id of my object to this view model because the view model will be resolved from the target view data context. Therefore my new page will open with the correct view model but will not display anything because it does not know about the object to load.

There is actually this solution to which Laurent replied, but has it has been said it is still not really satisfactory. For example it would not work in a scenario where your view model instance are not singletons.

So I wanted to know if anybody got some tips and tricks to get it to work with no workarounds or if Laurent got another solution :-)