Pass parameters from ConfirmNavigationRequest to NavigationService

Topics: Prism v4 - WPF 4
May 27, 2012 at 8:36 AM

I have a viewmodel that implements IConfirmNavigationRequest and I need to pass information from this viewmodel to a navigation broker class that I have, which is not coupled to any specific views or viewmodels.

Instead the navigation broker class has access to the IRegion of interest as well as to the IRegionNavigationService.

ViewModel Adding Parameters to Uri

    public override void ConfirmNavigationRequest(NavigationContext navigationContext,
                                                 
Action<bool> continuationCallback)
   
{
        _verificationCount
++;
        navigationContext
.Parameters.Add("Count", _verificationCount.ToString());
        continuationCallback
(Verify());
   
}

A Navigation Broker that Needs To Access the Passed Parameters

    // Some method
    _region
.RequestNavigate(new Uri(_nextView, UriKind.Relative), NavigationCallback);

   
private void NavigationCallback(NavigationResult navigationResult)
   
{            
       
if (navigationResult.Error == null)
       
{
           
if (navigationResult.Result == true)
           
{
               
// Need to evaluate the Count argument here
               
// int count = ...
               
// if (count < 5)
               
QueueNextView();                    
           
} else
           
{
               
Debug.WriteLine("Navigation Cancelled");
           
}
       
}
       
else
       
{
             
Debug.WriteLine("Navigation Error");                
       
}
   
}

How to Access Parameter Through Region or NavigationService, Outside ViewModel?

  • I cannot find a way to access NavigationContext through NavigationService or Region?
  • I also tried this _region.NavigationService.Journal.CurrentEntry.Uri.OriginalString but it did not show any query information, just the registered View string name
Developer
May 28, 2012 at 6:20 PM

Hi,

Based on my understanding of your scenario you could access the passed parameters from the NavigationResult object in your NavigationCallback method, as the NavigationResult class defines properties that provide information about the navigation operation. Among these properties you could find the Context property which provides access to the NavigationContext and the parameters it contains.

For example you could access your parameter like this:

navigationResult.Context.Parameters["Count"];
I hope you find this useful,

Agustin Adami
http://blogs.southworks.net/aadami

May 31, 2012 at 10:31 AM

That seems to be spot on! I'll try it, thanks!