Sharing viewmodel to multiple views using Caliburn.Micro in WP7

Apr 8, 2011 at 2:02 AM
Edited Apr 8, 2011 at 2:02 AM

Hi there,

I am currently working on a project which requires multiple views of the same viewmodel. Let me describe this way:

- ViewModel: CustomerDetailsViewModel.cs (inherited from Screen class)
- View: CustomerDetails.cs (this view has CustomerDetailsViewModel as datacontext and this set automatically by Caliburn.Micro)
- View: CustomerInfo.cs (now this is the view where I want to share CustomerDetailsViewModel, which could have some data already modifed via CustomerDetails view)

I am currently using NavigationService to navigate to CustomerInfo view. Is there any way to pass the reference of current viewmodel to the view which user is navigating to in caliburn.micro?

Thanks in advance

Apr 8, 2011 at 2:37 AM

There's not built-in way to do that unfortunately. It's complicated by the way the phone insists on doing navigation. As a solution, you might consider having the first screen stash the view model somewhere. Then the second screen would just do a "lookup" to find it. Does that make sense? I'm going to try and improve this scenario in future releases. It's a solved problem in Silverlight...but it's more complex and harder to generalize on the phone.

Apr 8, 2011 at 8:05 PM

I see, ok then for now I am going to serialize/deserialize object that is being used to store the data when navigating to the part view but it would definitely great to solve this by using built-in functionality.