Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

New Post: Share the same instance of a viewmodel between two other viewmodels?

$
0
0

Consider that I have these view models:

AViewModel
  - ContentControl
BViewModel
  - ContentControl
CViewModel

Where A/BViewModel derive from Conductor<Screen>.Collection.AllActive and are different views of different viewmodels, except for one small area of common functionality, represented by CViewModel. When A/BViewModel get the instance of CViewModel, they set its Parent to themselves.

At the moment I have things working ok, as long as I configure my IoC container to provide unique instances of CViewModel.

I'd like to share the instance of CViewModel between A/BViewModel, such that when I switch between AViewModel and BViewModel (e.g. in the Shell) that CViewModel displays and behaves correctly.

If I set CViewModel to not be unique, or to be a singleton, when AViewModel is displayed I can see CViewModel, and then if I switch to BViewModel I can also see CViewModel (with already loaded data), but if I then switch back to AViewModel, the area where CViewModel should be is blank.

Am I doing something wrong, or is there a better way of handling this?


Viewing all articles
Browse latest Browse all 1760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>