How to defer navigation in PRISM

Topics: Prism v4 - Silverlight 4
Aug 30, 2011 at 11:21 PM

Hello, 

I am trying to implement "ConfirmNavigation", which I was able to do. 

In one of my modules, if they user try to navigate but there are changes to the object, I want to confirm that the user wants to save the data before navigation. 

I have the confirmation working, and I have it saving, but since I use "Confirm Navigation" it moves to the next page, before the saving is done.

In Chapter 8: Navigation of the PRISM documentation on MSDN:

If you want to defer navigation, you can store a reference to the continuation callback you can then call when the interaction with the user (or web service) completes. The navigation operation will be pending until you call the continuation callback.

I am not sure I am following this correctly, can someone please post a simple code on how you can defer navigation please.

Thank you in advance.

 

 

Developer
Aug 31, 2011 at 3:29 PM

Hi,

You can find more information about this in this article from Karl Shifflett.

Also you might find this samples helpful:

I hope you find this useful.

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

Aug 31, 2011 at 4:32 PM

Thanks for your response.

I am able to get the confirmation to show; that is not the issue. 

I want to save the data on the view before it navigates to the next page.   What is currently taking place is that the confirmation message shows up, I ask the user if they want to save the data, if yes, I want to pause until the saving is done, just in case there is an error so we can inform the user.

I am able to save the data, but since the call is async, the completion of saving takes place after the user navigated, I want to stop that. 

The example and the links you sent (I already had completed the training kit) only explains how to show the confirmation and act accordingly. 

I am looking for example to defer the navigation till the save is complete. 

Below is what I am trying to implement but I am not successful.

In Chapter 8: Navigation of the PRISM documentation on MSDN:

If you want to defer navigation, you can store a reference to the continuation callback you can then call when the interaction with the user (or web service) completes. The navigation operation will be pending until you call the continuation callback.

 

 

 

 

 

Developer
Sep 1, 2011 at 5:53 PM

Hi,

Based on my understanding of your scenario, you could subscribe to the completed event for your save data async method, and make the call to the continuation callback in the handler for this event. This way the navigation operation will be pending until you have finished saving the data.

We've created a sample application that portrays this (based on the Prism Training Kit, Navigation HOL, Exercise 3). In our sample, we have a sample database service, which simulates a save operation. In the ConfirmNavigationRequest method, we call the sample SaveDataAsync method instead of the continuation callback, and in the handler of the SaveDataCompleted event, we do call the continuation callback (which we previously stored).

You can find the sample in my Skydrive account, under the  name ConfirmationCallbackSample.

Please let us know if we have misunderstood your scenario.

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

Sep 1, 2011 at 6:15 PM

Thank you so much for your prompt response.   I have not had a chance to look at the solution, but I really appreciate your help. 

Have a great weekend.

And thanks again.