2011-03-01 63 views

回答

3

我认为你的仪表板本质上是你的shell。在这种情况下,您可以引导您的LoginViewModelLogin方法,登录成功后,您可以使用Caliburn.Micro WindowManager显示DashboardViewModel并关闭LoginViewModel

喜欢的东西(使用MEF):

Bootstrapper.cs

public class Bootstrapper : Caliburn.Micro.Bootstrapper<ILoginViewModel> 
{ 
    ... 
} 

LoginViewModel.cs

public class LoginViewModel : Screen, ILoginViewModel 
{ 
    private readonly IWindowManager windowManager; 

    private readonly IDashboardViewModel dashboardViewModel; 

    [ImportingConstructor] 
    public LoginViewModel(IWindowManager windowManager, IDashboardViewModel dashboardViewModel) 
    { 
     this.windowManager = windowManager; 
     this.dashboardViewModel = dashboardViewModel; 
    } 

    public void Login() 
    {    
     // if login success... 
     this.windowManager.ShowDialog(this.dashboardViewModel); 
     this.TryClose(); 
    } 
} 
+0

我还没有这么想,但现在你提到它使仪表板的外壳可能会解决我遇到的大多数问题。 – 2011-03-01 10:38:51

+0

我很抱歉,但刚才我注意到了一些错误。我的窗口管理器没有简单的Show方法。 – 2011-03-01 10:58:07

+2

已更新。使用Silverlight你有一个ShowDialog,ShowNotification和ShowPopup。 ShowDialog显示指定视图模型的模态对话框,因此您可能需要切换逻辑并引导您的DashboardViewModel,然后如果用户未通过身份验证,请使用WindowManager.ShowDialog方法显示LoginViewModel(以便它位于仪表板顶部)。用户在成功登录之前将无法越过此模式屏幕,您只需关闭该对话框即可。 – devdigital 2011-03-01 11:03:06

2

我只是在我增加了一个非常简单的登录例子SL4工程“实验室库“为Caliburn.Micro。

https://github.com/jenspettersson/Caliburn.Micro.Labs/tree/master/src/Login

它使用罗布艾森伯格使用在他的“游戏库”为例,视图之间切换显示类。

在Login()方法中,它告诉我的Shell(您的仪表板?)显示我的LoginResultViewModel并设置登录结果消息。

yield return Show.Child<LoginResultViewModel>().In<IShell>().Configured(c => c.ResultMessage = "Successfully logged in!"); 

检查我的github回购代码。

最近我还没有使用Caliburn.Micro,所以我绝不是专家,但这种方式对我很有用。

∥焦

编辑:这回答了如何在视图之间进行导航,如果你想显示一个“弹出”显示,如果登录成功,去与其他recomendations。

+0

谢谢,以后肯定会有用。 – 2011-03-01 11:19:54

相关问题