I am looking to get MVVMLight focusing on Home windows Phone 7 and getting a little problem getting my mind round the paradigm.
The scenario It should follow is: 1.) Once the primary view model loads, a note is distributed through the MVVM Light Messenger to check on for the existence of a database 2.) The content is received through the ViewModel and when there's not database, a note is distributed to the vista through the messenger to exhibit the install View (to navigate into it) 3.) The Installer View is proven through the first View
The issue appears to become an order by which occasions are known as. The vista effectively inspections for the existence of a database and send the content, however the viewmodel has not been initialized yet (breakpoint in constructor is not hit once the message is distributed), therefore the form is not proven. Shall We Be Held handling this the proper way, or must i just look for the presence of the database within the View?
The Messenger are only able to send messages to things which do appear in memory (side note, I'm thinking about adding some "offline messenging" solution, but it's really merely a vision, not really a blueprint yet).
In MVVM Light, how a VM is wired towards the view in XAML, the VM is going to be introduced to existence very early (the moment InitializeComponent is hit within the code behind). If you want the VM to become produced earlier, that can be done within the ViewModelLocator. I will reveal that inside my MIX11 session (Deep Dive MVVM) check the recording when it's released (I'll bring it up on my small blog http://blog.galasoft.ch).
If you're not using MVVM Light's method of binding view and VM, and also the VM doesn't appear in memory yet, one of the ways would be to "cache" the content for later. Produce a lightweight object that is available exclusively with regards to finding the message, and also to store it. Then, once the VM is produced, retrieve the content. it is a message queue, if you would like.
Hopefully this can help, Laurent