I have a mvvm(model view viewmodel) silverlight application that has several views that need to be loaded into ContentControls (i made it all in expression blend). What i dont know how to do is, for example, to load one view (user control) in one content control by clicking a button from another view that is in another content control. To make it easier to understand the problem, i need to do something similar to this:
http://www.codeproject.com/KB/silverlight/BlendableVMCom.aspx
with that difference that child1 and child2 are supposed to be loaded into theirown content controls by clicking Call child1 or call child2 buttons.
and example would be appreciated. Thanks in advance!
This example is very simplified, but I think you now how to adjust it to your application.
The main view:
I haven’t created separated views as user controls, here are just borders, which can be replaced by real views.
Different view models for different views in code behind:
First view model conains the command which sends the message to another view model:
To make this example work, download the MVVM Light library.
The second view model receive the message and creates a view for its property:
Again, it is possible to use clr object instead of controls and apply data templates in xaml, but there will not be enough space to provide all the resulting code.
So that is all, the main idea is a some kind of event aggregator, which is the
Messengerclass in this particular case.Without the MVVM Light it will require more code:
In this example you must change the
DelegateCommandclass for something different. Other code will work for everyone.