Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Prism Navigation service with exceptions raised
namespace MyCompany
{
public partial class App
{
public App(IPlatformInitializer initializer)
: base(initializer)
{
}
protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry)
{
base.RegisterRequiredTypes(containerRegistry);
containerRegistry.RegisterScoped<INavigationService, PageNavigationRaisingExceptionService>();
containerRegistry.Register<INavigationService, PageNavigationRaisingExceptionService>(NavigationServiceName);
}
}
}
using System;
using System.Threading.Tasks;
using Prism.Behaviors;
using Prism.Common;
using Prism.Ioc;
using Prism.Navigation;
namespace MyCompany.Navigation;
public class PageNavigationRaisingExceptionService : PageNavigationService
{
public PageNavigationRaisingExceptionService(
IContainerProvider container,
IApplicationProvider applicationProvider,
IPageBehaviorFactory pageBehaviorFactory)
: base(container, applicationProvider, pageBehaviorFactory)
{
}
protected override async Task<INavigationResult> GoBackInternal(
INavigationParameters parameters,
bool? useModalNavigation,
bool animated)
{
var result = await base.GoBackInternal(parameters, useModalNavigation, animated);
if (result.Exception != null)
{
throw result.Exception;
}
return result;
}
protected override async Task<INavigationResult> GoBackToRootInternal(INavigationParameters parameters)
{
var result = await base.GoBackToRootInternal(parameters);
if (result.Exception != null)
{
throw result.Exception;
}
return result;
}
protected override async Task<INavigationResult> NavigateInternal(
Uri uri,
INavigationParameters parameters,
bool? useModalNavigation,
bool animated)
{
var result = await base.NavigateInternal(uri, parameters, useModalNavigation, animated);
if (result.Exception != null)
{
throw result.Exception;
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment