This project has moved and is read-only. For the latest updates, please go here.

Using InitParams with MVVM Light

May 25, 2010 at 2:03 PM

If I use the MVVM light template (SL4) I find the mainviewmodel (mainviewlocator) is created before App.Aplication_Startup has been executed; therefore any initparams passed to silverlight are not present at createtime.

What are the recommended workflow for this scenario (I need various values from the hosting (asp) application, before the viewmodel is created)


May 27, 2010 at 7:21 PM


The ViewModelLocator is created very early, but nothing forces you to create the ViewModels in the ViewModelLocator's constructor. Instead, add a "Create" method, which takes the HTML parameters as argument, and pass these arguments to the MainViewModel's constructor.

This is the main advantage of the ViewModelLocator pattern: You have total control over the viewmodels' lifetime.