C# 在Caliburn Micro中切换ViewModels

C# 在Caliburn Micro中切换ViewModels,c#,wpf,mvvm,caliburn.micro,C#,Wpf,Mvvm,Caliburn.micro,我正在尝试使用Caliburn Micro制作一个WPF应用程序。我在整个页面上有一个带有ContentControl的ShellView。我已经在启动时在ShellView的ContentControl中显示了一个UserControl(基本上是一个登录页面)。登录后,我想关闭当前的ViewModel并在ShellView的ContentControl中显示另一个。如何做到这一点?您需要从Conductor类继承ShellViewModel,从Screen继承其他ViewModel(登录和Se

我正在尝试使用Caliburn Micro制作一个WPF应用程序。我在整个页面上有一个带有ContentControl的ShellView。我已经在启动时在ShellView的ContentControl中显示了一个UserControl(基本上是一个登录页面)。登录后,我想关闭当前的ViewModel并在ShellView的ContentControl中显示另一个。如何做到这一点?

您需要从Conductor类继承ShellViewModel,从Screen继承其他ViewModel(登录和SecondViewModel)。你可以阅读更多关于。比如说,

 public class ShellViewModel:Conductor<Screen> 

 public class UserControl1ViewModel: Screen 

 public class UserControl2ViewModel: Screen
<ContentControl x:Name="ActiveItem"/>
 ActivateItem(new UserControl2ViewModel());