棱镜登录对话框

时间:2012-02-09 21:10:03

标签: c# wpf prism

我使用Prism进行应用,需要登录对话框。要验证登录,我需要初始化Prism / MEF加载的一些应用程序数据,所以我不能把它放在App.xmal.cs中 OnStartUp所以我将登录对话框放在bootstrappers 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 个答案:

答案 0 :(得分:5)

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

这是我做的:

  1. 您没有登录代码。初始化shell并加载第一个模块。在我的情况下,第一个模块包含安全性。

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

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

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