Share ViewModel across Silverlight assemblies

Topics: Extensibility
Jun 30, 2011 at 12:07 AM

I am just starting out with Caliburn Mico so be gentle with me!

I am looking at Caliburn as an alternative to MVVMLight as I want to be able to share my ViewModels across multiple assemblies. 

For example, I have a several Views available in different assemblies that are available to users depending on their access rights in the application.  Normally it is one view per assembly.

Each view in the assembly needs to bind to a ViewModel in the main Silverlight app (or I can move the VM out to a different assembly, I don't mind).

In other words, from my separate assembly, I want to be able to bind to the ViewModel (probably using a locator) which is in the main app assembly.

Is this possible using the Caliburn framework, if so, can someone point me in the right direction either by showing me some code sharing a URL with me?

Many thanks



Jul 4, 2011 at 10:01 PM
Edited Jul 4, 2011 at 10:01 PM

I guess you are using View-First approach, that is you have an existing View and want to locate and bind the corresponding ViewModel (more on the difference between View-First and Model-First approach:
Am I correct?

If so, you just have to use the Bind.Model attached property on your Views:


<UserControl ...


This instructs CM to ask the IoC container for an instance of the VM registered with the specified key ("someContainerKey" in the example) and bind it to the View.
Make sure to register the VMs in the bootstrapper with opportune keys; how to do it depends on the IoC container you are using.

You may also want to have a look at the Caliburn.Micro.ViewFirst sample (in the source code).