Using InitParams with MVVM Light

May 25, 2010 at 1: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 6: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.