How do I implement the logic to navigate once the service result is returned

Topics: Prism v4 - WPF 4
May 1, 2013 at 1:48 AM
I am using Prism V4, MVVM, and Unity using C#.

In a bootstrapper, I have two views. Using the IRegionManager, I navigate between the first and the second view.

The first view contains a search box. The user types a string, clicks search. The first view passes the string over to the second view. The second view uses this string to call a service to get a list of items.

Everything works fine so far, but I would like to make this async that (also adding a ProgressIndicator). That is I do not want the application to lock when the user click on the search button.

I want the application to behave like so:

The user enters a search string, and clicks on search (I have implemented.)
The user should remain on the first view with the progress bar made visible (I have implemented.)
In the background the search should be making a async call to the DB. (Implemented)
Once the result is back from the service, the view should change to the second view with the result. (I have not been able to implement this)

How do I implement step 4 behavior?
May 2, 2013 at 7:07 PM

I believe you could find the IConfirmNavigationRequest interface provided by Prism useful. This interface defines a ConfirmNavigationRequest method which receives a callback as a parameter. This method will be invoked when you are navigate from the view / view model that implements it, and will interrupt the navigation process until the callback is invoked.) For example, if the first view implements this interface, the method will be invoked when navigating from the first view to the second. There, in the first view, you could show the progress bar, invoke the asynchronous operation to obtain the data and continue the navigation when the operation finishes.

You can find more information about the IConfirmNavigationRequest interface in the following section of the documentation:
Damian Cherubini
May 4, 2013 at 3:19 AM
Edited May 4, 2013 at 3:20 AM
I see. I will use this interface to notify me when the async operation is completed. But, since I am performing the operation on View1.ViewModel and displaying the result (collection of a type) on View2.View, how would I be able to retrieve the result on View2?

I can only send a query string to View 2. And, in this case since I will send the query string to the async operation, I don't have to send any query string to View2.

I am guessing, I need to create an ObservableCollection of the type. On View1.ViewModel I load this collection; on View2.View I display it. Is this correct?
May 6, 2013 at 5:59 PM

I believe you will need to implement a communication mechanism between both view models or abstract the logic of obtaining and storing the data in a different component that could be used by both view models (e. g. a Shared Service that works as a data repository).

You can find more information about Shared Services and other communications mechanism in the following chapter of the documentation:
I hope this helps,

Damian Cherubini