我使用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
}
Run Code Online (Sandbox Code Playgroud)
我很难评估是否有任何陷阱或缺点,任何人都有评论
是的,我有同样的困境.您只有一个RootVisual,但您必须强制用户登录.这是一个常见的情况,并没有真正解决.
这是我做的:
代码就像你没有登录.初始化shell并加载第一个模块.在我的情况下,第一个模块包含安全性.
当您的"系统"或您称之为模块的任何模块加载时 - 编写代码Initialize()来调用您的登录程序,在我的情况下,这是SecurityService.
我使用RegionPopupManager(与PRISM捆绑的StockTrader RI项目中的示例)来显示模态弹出交互.
登录后 - 只需隐藏弹出窗口并继续加载其他模块,填充区域等
| 归档时间: |
|
| 查看次数: |
2123 次 |
| 最近记录: |