viewer20q
viewer20q

Reputation: 71

Prism RequestNavigate does not work

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.

Upvotes: 7

Views: 11239

Answers (3)

Golvellius
Golvellius

Reputation: 1928

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.

Upvotes: 2

Rob Bagby
Rob Bagby

Reputation: 139

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.

Upvotes: 3

Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104801

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

Upvotes: 23

Related Questions