I use MVVM Light for my WP7 apps, it's great! I implement the following navigation service for controlling navigation from the view model layer:
Part 2 Here
The main problem I've faced is that I often want to pass parameters to the target view's view model to prepare it for what it needs to do. It is possible to access properties in the target view model through the ViewModelLocator as each view model has a static property used for the view binding via the non-static properties, however this means that the view models are tightly coupled through the VML and it seems like a bit of a hack.
The example code is from an article page which requires navigation to a links page.
It's possible to fire a message out before navigating to pass parameters to the target view model, however, if the target view has never been hit, the associated vm will not not have instantiated so will not receive the message! This can be worked around by calling the VML CreateXXX method however this is still not the elegant solution I was hoping for.
To solve this problem, I figured that when a VM instantiates, ask if any other VM has any parameters for it then register a message pipe for parameters when it is instantiated.
I created a message which would take a parameter to pass from the source to the target or an action to request a parameter from the source, by the target:
First off messages need registering (at constructor stage) so that the target VM may message back one it constructs:
That's it, seems like a nice loosely coupled way of initialising a view model on navigation.