gpt4 book ai didi

c# - 如何在 Prism 6 的 Shell 顶部显示登录模式窗口?

转载 作者:行者123 更新时间:2023-12-02 14:11:04 25 4
gpt4 key购买 nike

我的 Prism 6 WPF MVVM 模块化应用程序(使用 Unity DI)必须在加载后在 Shell 顶部显示模式登录窗口,以询问用户用户名和密码。 (这是我工作的生产目标的要求。)我看过http://compositewpf.codeplex.com/discussions/58292的帖子但这篇文章描述了如何在显示 Shell 之前显示登录窗口,但我的应用程序必须在 Shell 之上显示登录窗口(因此 Shell 必须显示在背景上)。此外,这篇文章描述了如何在 Prism 2 中执行此操作,但我使用 Prism 6 并且我想使用 Prism 窗口(WPF)作为登录窗口的 View 。以下是我的应用程序结构:

enter image description here

其中“AuthrizationView.xaml”是 Prism 窗口(WPF),它是登录窗口,在解决方案中的“Authorization”项目的 ViewModels 文件夹中具有 AuthrizationViewModel View 模型,在 Models 文件夹中具有 AuthrizationModel 模型。 MainWindow.xaml 是解决方案中“FlowmeterConfiguration”项目的 ViewModels 文件夹中具有 MainWindowViewModel View 模型的 Shell。所以我这里有以下问题:

  1. 如何在 Shell 上显示登录模式窗口?
  2. 当用户在相应的框中输入用户名和密码后单击此窗口中的“登录”按钮时,如何关闭登录窗口?
  3. 如果用户不想登录,点击窗口中的“取消”按钮时如何关闭登录窗口?
  4. 是否可以通过单击 Shell 中相应的菜单项来一次又一次地激活登录窗口以更改用户?
  5. 我可以为此类菜单项添加键盘快捷键支持吗?

我们将非常感谢您的帮助。

最佳答案

您应该使用InteractionRequest<T>键入以在 XAML 中触发交互请求,这将显示一个新的模式窗口。用户输入数据后,它会将其传输回调用者。

查看我之前关于此主题的答案,发现 here .

如果您需要将交互请求的输入传输回调用 View ,则需要实现一个继承自 IConfirmation 的类。或Confirmation并定义其字段,然后在回调中使用它。

从我的其他答案示例来看,那就是

public class LoginConfirmation : Confirmation 
{
public string Login { get; set; }
public SecureString SecurePassword { get; set; }
}

public InteractionRequest<LoginConfirmation> LoginConfirmationRequest
{ get; private set; }
this.LoginConfirmationRequest = new InteractionRequest<LoginConfirmation>();

然后通过

调用请求
this.LoginConfirmationRequest.Raise(
new LoginConfirmation { Title = "Please enter your login" }, OnLoginResponse);

protected virtual void OnLoginResponse(LoginConfirmation context)
{
if(!context.Confirmed)
{
// user canceled
return;
}

// user confirmed login
this.myAuthorizationService.Login(context.Login, context.SecurePassword);
}

您的登录窗口的 View 模型需要实现IInteractionRequestAware能够将数据传递回您的 shell。

public class LoginViewModel : BindableBase, IInteractionRequestAware
{
public Action FinishInteraction { get; set; }

private INotification notification;
public INotification Notification
{
get { return this.notification; }
set { SetProperty(ref notification, value); }
}
}

哪里LoginConfirmation将位于通知属性中,您可以在调用FinishInteraction()之后在那里设置它的值窗口将关闭并返回到您的 shell 或您调用它的任何地方

关于c# - 如何在 Prism 6 的 Shell 顶部显示登录模式窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35954640/

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