IAsyncNavigationAware: Asynchronous region navigation with continuations

Topics: Prism v4 - Silverlight 4, Prism v4 - WPF 4
Aug 7, 2012 at 1:14 PM

The region navigation mechanism of Prism is a very powerful and flexible mechanism for navigating between views in a region.

Unfortunately, the region navigation mechanism of Prism only supports synchronous navigation between views. Sometimes however,it is necessary that some asynchronous code is executed during the navigation from one view to another. An example is a wizard where between two wizard steps an asynchronous web service call has to be performed to validate input or to process some data.

To overcome this limitation, I've created the IAsyncNavigationAware interface and corresponding ASyncRegionNavigationService. Similar to Prism's IConfirmNavigationRequest interface (which does execute asynchronously), the interface uses continuations to proceed the navigation process:

public interface IAsyncNavigationAware
{
    void NavigateTo(NavigationContext navigationContext, Action continuationCallback);

    bool IsNavigationTarget(NavigationContext navigationContext);

    void NavigateFrom(NavigationContext navigationContext, Action continuationCallback);
}

As you can see, this interface uses continuations for the two navigation actions. This way, asynchronous code can be executed when navigating to or navigating from a view/viewmodel and when this code completes, calling continuationCallback() will continue the navigation process.

I've also created the IConfirmAsyncNavigationRequest interface which is similar to IConfirmNavigationRequest but now derives from IAsyncNavigationAware.

I've also created the AsyncNavigationAwareBehavior region behavior which takes care of attaching the RegionAsyncNavigationService to your regions.

Please let me know if anyone is interested or if this can perhaps added to the source code of Prism.

Kind regards,

Merijn

Developer
Aug 7, 2012 at 6:41 PM
Edited Aug 7, 2012 at 6:41 PM

Hi Merijn,

What you are describing seems to be an interesting implementation that allows the usage of asynchronous services in the OnNavigatedFrom and OnNavigatedTo methods.

In my opinion, you could create a work item in the issue tracker section as a suggestion, where you can upload your implementation. There, other users could vote you suggestion and the Prism team could analyze it for future releases.

Thanks,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Aug 9, 2012 at 4:19 PM

Hi Damian,

Thanks for your reply. As you suggested I've created a work item for this.

Kind regards,

Merijn