I am trying to make a WPF application using Caliburn Micro. I have a ShellView with a ContentControl in it on the full page. I am already showing on startup an UserControl in the ShellView s ContentControl(Basically it is a LogIn Page). After login, I want to close the current ViewModel and show another one in the ShellView s ContentControl. How can I do this?
1
votes
1 Answers
1
votes
You need to begin by inheriting your ShellViewModel from Conductor class and other ViewModels (Login and SecondViewModel) from Screen. You can read more on Screen and Conductors. For example,
public class ShellViewModel:Conductor<Screen>
public class UserControl1ViewModel: Screen
public class UserControl2ViewModel: Screen
The ShellViewModel would be conducting between different Screens and has inherited from Caliburn.Micro's Conductor class. When you show a screen, the conductor makes sure it is properly activated. If you are transitioning away from a screen, it makes sure it gets deactivated.
The second change you need to make is in the Context Control in ShellView by binding it to Conductor's Active Item.
<ContentControl x:Name="ActiveItem"/>
Finally, you could make use of Conductor's ActivateItem method to switch between screens.
ActivateItem(new UserControl2ViewModel());