Reputation: 42125
I've composed the UI of my Caliburn.Micro application such that toolbar buttons have their own View and ViewModel.
In the examples I've seen, to activate a new screen, a method in the shell calls Conductor.ActivateItem
, passing in the viewmodel instance, however in my case the ToolbarButtonViewModel.Submit()
method is on a class that isn't the shell.
What's the best way of activating screens from a class other than the shell?
Upvotes: 3
Views: 2623
Reputation: 3999
You should consider using the EventAggregator. Create a message which the main conductor handles and send it from the tool bar vm. When the message is recieved by the main conductor, activate the screen that it specifies.
Upvotes: 14
Reputation: 34349
This sounds like a case for inter-viewmodel communication (between the toolbar view model, and the shell viewmodel). Depending on how loosely coupled you wish the code to be, you could either:
ShellViewModel
has a reference to the ToolBarViewModel
instance, subscribe to the ToolBarViewModel
's event in the ShellViewModel
to detect the submit, and pass the new screen instance to the delegate instance.EventAggregator
included in Caliburn.Micro). Subscribe to the event in the ShellViewModel
, and publish the event in the ToolBarViewModel
ToolBarViewModel
in the ShellViewModel
(presumably you'll have to use the Conductor<T>.Collection.AllActive
type). The ToolBarViewModel
will then be a Screen
and have a Parent
property (yes, this is ugly).Upvotes: 1