Prism RequestNavigate does not work

后端 未结 3 964
一生所求
一生所求 2021-01-02 18:40

In each view

public partial class View2 : UserControl, IRegionMemberLifetime, INavigationAware
{

  public bool KeepAlive
  {
    get { return false; }
  }

         


        
相关标签:
3条回答
  • 2021-01-02 18:41

    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.

    0 讨论(0)
  • 2021-01-02 18:46

    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 讨论(0)
  • 2021-01-02 18:48

    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
        }
    );
    
    0 讨论(0)
提交回复
热议问题