Jonas Van der Aa
Jonas Van der Aa

Reputation: 1461

How to navigate from one ViewModel to another in Caliburn.Micro?

I want to navigate from a login screen to the dashboard in my Silverlight OOB app.

I started using Caliburn.Micro but now I'm having doubts seeing as all I can use is the Conductor. Or am I missing something?

Note: I changed constructor to Conductor as originally intended. This is what you get for not proofreading your questions.

Upvotes: 1

Views: 1005

Answers (1)

devdigital
devdigital

Reputation: 34349

There are several ways you could display a login screen, probably the nicest is to initiate it from your ShellViewModel. So, your ShellViewModel would have a dependency on your LoginViewModel, which you could inject as an abstraction (ILoginViewModel), or better still use an abstract factory instead, and inject that into your ShellViewModel constructor.

Either way, once you have an instance of your LoginViewModel in the ShellViewModel, you can display it either as a modal dialog box (in which case use the Caliburn.Micro WindowManager.ShowDialog method - inject this dependency as an IWindowManager abstraction), or display the login view as part of your shell views main content area, in which case your ShellViewModel would be a conductor, and will activate an instance of your LoginViewModel with the ActivateItem method.

Once you have received input from your LoginViewModel, either as a modal dialog or conducted view, you can display your DashboardViewModel as appropriate using the ShellViewModel as a conductor.

Upvotes: 3

Related Questions