【问题标题】:PRISM 5 : IConfirmNavigationRequest methods called more than oncePRISM 5:多次调用 IConfirmNavigationRequest 方法
【发布时间】:2015-03-05 13:38:41
【问题描述】:

我正在使用 PRISM 和 Unity 扩展。

WPF 按钮命令调用以下代码并显示对话框:

 private void LaunchDialog() 
 {
        Bootstrapper bootstrapper = new  Bootstrapper();
        bootstrapper.Run();
        bootstrapper.MyShell.Owner = Application.Current.MainWindow;
        bootstrapper.MyShell.ShowDialog();
} 

当我第一次单击LaunchDialog 时,PRISM 导航方法OnNavigatedFromOnNavigatedTo 调用一次。我关闭对话框,

当我下次单击 LaunchDialog 时,PRISM 导航方法 OnNavigatedFromOnNavigatedTo 会被调用两次。我关闭对话框,

如果我第三次单击LaunchDialogPRISM 导航方法OnNavigatedFromOnNavigatedTo 将被调用三次。我关闭对话框,

如何摆脱这种行为?这样即使用户多次单击LaunchDialog,导航方法在第一次启动时也只会被调用一次。

【问题讨论】:

  • 我认为您的对话框实例未正确处理。检查一些事件或任何静态引用。
  • 我是否理解正确,您创建了一个引导程序并以在您已经运行的应用程序中单击按钮时调用的方法运行它?那么,这是一个完全错误的方法。

标签: c# wpf prism


【解决方案1】:

我刚刚添加了 bootstrapper.Container.RemoveAllExtensions() 来摆脱这种行为。

private void LaunchDialog() 
{
        Bootstrapper bootstrapper = new  Bootstrapper();
        bootstrapper.Run();
        bootstrapper.MyShell.Owner = Application.Current.MainWindow;
        bootstrapper.MyShell.ShowDialog();
        bootstrapper.Container.RemoveAllExtensions();
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-20
    • 2013-10-22
    • 1970-01-01
    • 2011-01-27
    • 2011-04-17
    • 2012-11-13
    • 1970-01-01
    相关资源
    最近更新 更多