Prism RequestNavigate不起作用

vie*_*20q 7 wpf prism

在每个视图中

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;
  }

}
Run Code Online (Sandbox Code Playgroud)

初始化:

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));
Run Code Online (Sandbox Code Playgroud)

我正在关注开发者指南,如果视图存在,它不会更改视图.

Shi*_*mmy 13

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

我建议你为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
    }
);
Run Code Online (Sandbox Code Playgroud)

  • 7年后,我在想,让我们回答这个问题.很简单,帮助我轻松解决这个问题,然后我想我是那个回答它的人...... (5认同)
  • https://www.reddit.com/r/ProgrammerHumor/comments/19bcozs/goingfullcircle/ (5认同)