IConfirmNavigationRequest and RIA Services

Topics: Prism v4 - Silverlight 4
Dec 14, 2010 at 4:22 PM

Untitled Page


I'm using Prism Region Navigation with Silverlight Frame navigation Navigation as described in http://blogs.msdn.com/b/kashiffl/archive/2010/10/05/integrating-prism-v4-region-navigation-with-silverlight-frame-navigation.aspx.

The simple case is working as you'd expect but I want to call a RIA service method in my ConfirmNavigationRequest method.The problem is that OnNavigatingFrom in the FrameNavigationWrapperPage isn't set up to handle ConfirmNavigationRequest not being totally synchronus. I.e. when ConfirmNavigationRequest returns, if the result is not present then the method will continue and skip past the cancellation step. I'll try and illustrate with a code sample.

Here is the OnNavigateFrom from the frame wrapper page...

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{ this.Execute<IConfirmNavigationRequest>(
    ina =>     {      bool? result = null;
        var ignore = false;
        ina.ConfirmNavigationRequest(          this.CreateNavigationContext(e.Uri),
            r =>             {              if (!ignore)
                {                  result = r;                 }             });
            ignore = true;
          if (result == false)
            { e.Cancel = true;
} }); }

Now if my view model looks like this...

public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
{ // synchronus code continuationCallback(false);           }

Then the result is set before "if(result == false)" is reached and e.Cancel is set correctly.

If my view model looks like this however...

public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
{ this.riaContextThing.RiaMethod(
(x) =>
                { continuationCallback(x);                  }); }

Then continuationCallback isn't called until the RiaService returns and when "if(result == false)" is reached, result is null and anything that happens in continuationCallback is ignored.

Dec 14, 2010 at 7:57 PM
Edited Dec 14, 2010 at 7:58 PM


As explained in the Navigation chapter from the Prism MSDN documentation, "It should be noted that after the interaction request event is raised, the ConfirmNavigationRequest method immediately returns so that the user can continue to interact with the UI of the application. When the user clicks the OK or Cancel buttons on the pop-up window, the callback method of the interaction request is made, which in turn calls the continuation callback to complete the navigation operation. All the methods are called on the UI thread. Using this technique, no background threads are required. Using this mechanism, you can control if the navigation request is carried out immediately or is deferred, pending an interaction with the user or some other asynchronous interaction (for example, as a result of a web service request). To enable navigation to proceed, you can simply call the continuation callback method, passing true to indicate that it can continue. Similarly, you can pass false to indicate that the navigation should be canceled."

You can read more about this in the "Confirming or Cancelling Navigation" section of the aforementioned chapter. You might also find this article from Karl Shifflett useful to your scenario.

I hope you find this helpful.

Guido Leandro Maliandi


Dec 15, 2010 at 8:46 AM

Hi Guido

Thanks for showing an interest but what you say doesn't seem to apply when you integrate Silverlight Frame Navigation with Prism Navigation a la the link provided in my first post and again here. The link is actually a Karl Shifflett link which follows up the one you provided.

Also, I'm not providing the user with an OK/Cancel dialog box, I want to make a RIA services call.




Dec 17, 2010 at 7:13 PM


For those who are experiencing this issue, it could be useful to know that it's being discussed in the comments of this post from Karl Shifflett, who has announced that he's working on a solution to this.

Guido Leandro Maliandi