Prism RequestNavigate 不起作用

发布于 2024-11-06 01:43:32 字数 909 浏览 1 评论 0原文

在每个视图中

public partial class View2 : UserControl, IRegionMemberLifetime, INavigationAware
{

  public bool KeepAlive
  {
    get { return false; }
  }

  bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
  {
    return true;
  }
  void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
  {
    // Intentionally not implemented.
  }
  void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
  {
    this.navigationJournal = navigationContext.NavigationService.Journal;
  }

}

初始化:

container.RegisterType<object, View1>("View1");
container.RegisterType<object, View2>("View2");

regionManager.RequestNavigate("Window1", new Uri("View1", UriKind.Relative));
regionManager.RequestNavigate("Window2", new Uri("View2", UriKind.Relative));

我遵循开发人员指南,如果视图存在,它不会更改视图。

In each view

public partial class View2 : UserControl, IRegionMemberLifetime, INavigationAware
{

  public bool KeepAlive
  {
    get { return false; }
  }

  bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
  {
    return true;
  }
  void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
  {
    // Intentionally not implemented.
  }
  void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
  {
    this.navigationJournal = navigationContext.NavigationService.Journal;
  }

}

Initialize:

container.RegisterType<object, View1>("View1");
container.RegisterType<object, View2>("View2");

regionManager.RequestNavigate("Window1", new Uri("View1", UriKind.Relative));
regionManager.RequestNavigate("Window2", new Uri("View2", UriKind.Relative));

I am following the developer guide, it does not change the view if view exists.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只等公子 2024-11-13 01:43:32

您确定视图已由容器填充吗?

我建议您为 RequestNavigate 方法提供回调,以便您能够通过 NavigationResult

regionManager.RequestNavigate
(
    "Window1",
    new Uri("View2", UriKind.Relative),
    (NavigationResult nr) => 
    {
        var error = nr.Error;
        var result = nr.Result;
        // put a breakpoint here and checkout what NavigationResult contains
    }
);

Are you sure the view gets populated by the container?

I would suggest you to provide a callback for the RequestNavigate method, so you'll be able to track what happens with your view thru the NavigationResult:

regionManager.RequestNavigate
(
    "Window1",
    new Uri("View2", UriKind.Relative),
    (NavigationResult nr) => 
    {
        var error = nr.Error;
        var result = nr.Result;
        // put a breakpoint here and checkout what NavigationResult contains
    }
);
今天小雨转甜 2024-11-13 01:43:32

我已经看到,如果我实现 IConfirmNavigateRequest 并且不调用 continutationCallback(true),导航会悄悄失败。

public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
    {
        //***Should have actual logic here
        continuationCallback(true);
    }

虽然这可能不是您的情况,但我通过调试 Prism 代码发现了这一点。我建议您这样做来找出您的问题。删除每个相关项目中对以下内容的引用。

  • Microsoft.Practices.Prism
  • Microsoft.Practices.Prism.Interactivity
  • Microsoft.Practices.Prism.MefExtensions
  • Microsoft.Practices.Prism.UnityExtensions

然后从 PrismLibrary DeskTop、Silverlight 或 Phone 目录(安装 PRISM 的位置)添加项目。然后参考这些项目。

I have seen that if I implement IConfirmNavigateRequest and do not call continutationCallback(true), the navigation fails quietly.

public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
    {
        //***Should have actual logic here
        continuationCallback(true);
    }

While this may not be your case, I figured this out by debugging through the Prism code. I would suggest you do this to figure out your issue. Delete the references to the following in each relevant project.

  • Microsoft.Practices.Prism
  • Microsoft.Practices.Prism.Interactivity
  • Microsoft.Practices.Prism.MefExtensions
  • Microsoft.Practices.Prism.UnityExtensions

Then add the projects from the PrismLibrary DeskTop, Silverlight or Phone directory (where you installed PRISM). Then reference these projects.

玉环 2024-11-13 01:43:32

这是您的问题:

bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext) => true;

如果您希望每次调用 RequestNavigate() 时都创建一个新视图并将其添加到您的区域,IsNavigationTarget() 必须返回 false 而不是 true 。

This is your problem:

bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext) => true;

If you want a new view to be created and added to your region each time you call RequestNavigate(), IsNavigationTarget() must return false instead of true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文