棱镜登录对话框

3

我在一个应用程序中使用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
        }

我很难评估是否存在任何陷阱或缺点,有人有评论吗?

1个回答

5

是的,我曾经也有同样的困惑。您只有一个RootVisual,但必须强制用户登录。这是一个常见的场景,实际上并没有得到很好的解决。

这是我所做的:

  1. 编写代码时不考虑登录。初始化shell并加载第一个模块。在我的情况下,第一个模块包含安全相关的内容。

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

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

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


1
感谢您的好评论。由于我正在开发桌面应用程序,所以现在我会坚持我的解决方案,但是我会在有时间时尝试您的解决方案。谢谢。 - klashagelqvist

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接