Prism登录对话框

本文关键字:对话框 登录 Prism | 更新日期: 2023-09-27 18:23:52

我将Prism用于应用程序,需要一个登录对话框。为了验证登录,我需要初始化Prism/MEF加载的一些应用程序数据,这样我就不能把它放在App.xmal.cs中OnStartUp,所以我把登录对话框放在引导程序InitializeShell中,就像这个

   protected override void InitializeShell()
        {

            Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            //// Authenticate the current user and set the default principal
            LoginDialog auth = new LoginDialog();
            auth.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            bool? dialogResult = auth.ShowDialog();
            // deal with the results
            if (dialogResult.HasValue && dialogResult.Value)
            {
                base.InitializeShell();
                Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
            }
            else
            {
                Application.Current.Shutdown(-1);
            }

#if SILVERLIGHT
            Application.Current.RootVisual = (Shell)this.Shell;            
#else
            Application.Current.MainWindow = (Shell)this.Shell;

            Application.Current.MainWindow.Show();
#endif
        }

我很难评估是否有任何陷阱或缺点,任何人都有评论

Prism登录对话框

是的,我也有同样的困境。您只有一个RootVisual,但您必须强制用户登录。这是一个没有真正解决的常见场景。

以下是我所做的:

  1. 代码就像你没有登录。初始化shell并加载第一个模块。在我的案例中,第一个模块包含安全性内容。

  2. 当你的"系统"或你称之为模块的东西被加载时,在Initialize()中编写代码来调用你的登录过程,在我的情况下,这就是SecurityService

  3. 我使用了RegionPopupManager(与PRISM捆绑在一起的StockTrader RI项目中的示例)来显示模式弹出交互。

  4. 登录时-只需隐藏弹出窗口并继续加载其他模块、填充区域等