开发者

Prism RequestNavigate does not work

开发者 https://www.devze.com 2023-03-03 12:33 出处:网络
I开发者_开发知识库n each view public partial class View2 : UserControl, IRegionMemberLifetime, INavigationAware

I开发者_开发知识库n 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.


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消