gpt4 book ai didi

c# - Prism 登录对话框

转载 作者:行者123 更新时间:2023-11-30 15:05:16 24 4
gpt4 key购买 nike

我将 Prism 用于应用程序并需要一个登录对话框。为了验证登录,我需要初始化一些由 Prism/MEF 加载的应用程序数据,所以我不能把它放在 App.xmal.cs 中OnStartUp 所以我像这样将登录对话框放在 Bootstrap 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
}

我很难评估是否有任何陷阱或缺点,谁有意见

最佳答案

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

这是我做的:

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

  2. 当您的“系统”或您称之为模块的任何东西加载时 - 在 Initialize() 中编写代码以调用您的登录过程,在我的例子中是 SecurityService

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

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

关于c# - Prism 登录对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9218815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com