private static async Task OnNavigatingToAsync(Page toPage, INavigationParameters parameters) { PageUtilities.OnNavigatingTo(toPage, parameters); await PageUtilitiesExtended.OnNavigatingToAsync(toPage, parameters); if (toPage is TabbedPage tabbedPage) { if (tabbedPage.CurrentPage is NavigationPage navigationPage) { PageUtilities.OnNavigatingTo(navigationPage.CurrentPage, parameters); await PageUtilitiesExtended.OnNavigatingToAsync(navigationPage.CurrentPage, parameters); } else { PageUtilities.OnNavigatingTo(tabbedPage.CurrentPage, parameters); await PageUtilitiesExtended.OnNavigatingToAsync(tabbedPage.CurrentPage, parameters); } } else if (toPage is CarouselPage carouselPage) { foreach (var child in carouselPage.Children) { PageUtilities.OnNavigatingTo(child, parameters); await PageUtilitiesExtended.OnNavigatingToAsync(child, parameters); } } }
/// <summary> /// When navigating inside a NavigationPage: Pops all but the root Page off the navigation stack /// </summary> /// <param name="navigationService">The INavigatinService instance</param> /// <param name="parameters">The navigation parameters</param> /// <remarks>Only works when called from a View within a NavigationPage</remarks> protected virtual async Task <INavigationResult> GoBackToRootInternal(INavigationParameters parameters) { var result = new NavigationResult(); try { if (parameters == null) { parameters = new NavigationParameters(); } parameters.GetNavigationParametersInternal().Add(KnownInternalParameters.NavigationMode, NavigationMode.Back); var page = GetCurrentPage(); var canNavigate = await PageUtilities.CanNavigateAsync(page, parameters); if (!canNavigate) { result.Exception = new Exception($"IConfirmNavigation for {page} returned false"); return(result); } List <Page> pagesToDestroy = page.Navigation.NavigationStack.ToList(); // get all pages to destroy pagesToDestroy.Reverse(); // destroy them in reverse order var root = pagesToDestroy.Last(); pagesToDestroy.Remove(root); //don't destroy the root page PageUtilities.OnNavigatingTo(root, parameters); await PageUtilitiesExtended.OnNavigatingToAsync(root, parameters); await page.Navigation.PopToRootAsync(); foreach (var destroyPage in pagesToDestroy) { PageUtilities.OnNavigatedFrom(destroyPage, parameters); PageUtilities.DestroyPage(destroyPage); } PageUtilities.OnNavigatedTo(root, parameters); result.Success = true; return(result); } catch (InvalidOperationException ex) { result.Exception = new Exception("GoBackToRootAsync can only be called when the calling Page is within a NavigationPage.", ex); return(result); } catch (Exception ex) { result.Exception = ex; return(result); } }
/// <summary> /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack. /// </summary> /// <param name="parameters">The navigation parameters</param> /// <param name="useModalNavigation">If <c>true</c> uses PopModalAsync, if <c>false</c> uses PopAsync</param> /// <param name="animated">If <c>true</c> the transition is animated, if <c>false</c> there is no animation on transition.</param> /// <returns>If <c>true</c> a go back operation was successful. If <c>false</c> the go back operation failed.</returns> protected virtual async Task <INavigationResult> GoBackInternal(INavigationParameters parameters, bool?useModalNavigation, bool animated) { var result = new NavigationResult(); try { NavigationSource = PageNavigationSource.NavigationService; var page = GetCurrentPage(); var segmentParameters = UriParsingHelper.GetSegmentParameters(null, parameters); segmentParameters.GetNavigationParametersInternal().Add(KnownInternalParameters.NavigationMode, NavigationMode.Back); var canNavigate = await PageUtilities.CanNavigateAsync(page, segmentParameters); if (!canNavigate) { result.Exception = new Exception($"IConfirmNavigation for {page} returned false"); return(result); } bool useModalForDoPop = UseModalNavigation(page, useModalNavigation); Page previousPage = PageUtilities.GetOnNavigatedToTarget(page, _applicationProvider.MainPage, useModalForDoPop); PageUtilities.OnNavigatingTo(previousPage, segmentParameters); await PageUtilitiesExtended.OnNavigatingToAsync(previousPage, segmentParameters); var poppedPage = await DoPop(page.Navigation, useModalForDoPop, animated); if (poppedPage != null) { PageUtilities.OnNavigatedFrom(page, segmentParameters); PageUtilities.OnNavigatedTo(previousPage, segmentParameters); PageUtilities.DestroyPage(poppedPage); result.Success = true; return(result); } } catch (Exception ex) { _logger.Log(ex.ToString(), Category.Exception, Priority.High); result.Exception = ex; return(result); } finally { NavigationSource = PageNavigationSource.Device; } result.Exception = new Exception("Unknown error occured."); return(result); }