Skip to content

Instantly share code, notes, and snippets.

@wldevries
Last active September 4, 2015 16:00
Show Gist options
  • Save wldevries/cb60ce0d516502113e45 to your computer and use it in GitHub Desktop.
Save wldevries/cb60ce0d516502113e45 to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
namespace Microsoft.Practices.Prism.Regions
{
public static class NavigationServiceMixins
{
public static async Task<NavigationResult> GoBack(this IRegionNavigationService service)
{
var tcs = new TaskCompletionSource<NavigationResult>();
EventHandler<RegionNavigationEventArgs> navigated =
(s, a) => tcs.SetResult(new NavigationResult(a.NavigationContext, true));
EventHandler<RegionNavigationFailedEventArgs> failed =
(s, a) => tcs.SetResult(new NavigationResult(a.NavigationContext, a.Error));
service.Navigated += navigated;
service.NavigationFailed += failed;
service.Journal.GoBack();
var result = await tcs.Task;
service.Navigated -= navigated;
service.NavigationFailed -= failed;
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment