/// <inheritdoc /> protected override async Task DoPush(Page currentPage, Page page, bool?useModalNavigation, bool animated, bool insertBeforeLast = false, int navigationOffset = 0) { switch (page) { case PopupPage popup: if (_applicationProvider.MainPage is null) { throw new PopupNavigationException(popup); } await _popupNavigation.PushAsync(popup, animated); break; default: if (_popupNavigation.PopupStack.Any()) { foreach (var pageToPop in _popupNavigation.PopupStack) { PageUtilities.DestroyPage(pageToPop); } await _popupNavigation.PopAllAsync(animated); } if (currentPage is PopupPage) { currentPage = PageUtilities.GetCurrentPage(_applicationProvider.MainPage); } await base.DoPush(currentPage, page, useModalNavigation, animated, insertBeforeLast, navigationOffset); break; } }
private void FireExposureNotificationEvent(int requestCode, bool isOk) { Action <IExposureNotificationEventCallback> action = requestCode switch { ExposureNotificationApiService.REQUEST_EN_START => new Action <IExposureNotificationEventCallback>(callback => { if (isOk) { callback.OnEnabled(); } else { callback.OnDeclined(); } }), ExposureNotificationApiService.REQUEST_GET_TEK_HISTORY => new Action <IExposureNotificationEventCallback>(callback => { if (isOk) { callback.OnGetTekHistoryAllowed(); } else { callback.OnGetTekHistoryDecline(); } }), ExposureNotificationApiService.REQUEST_PREAUTHORIZE_KEYS => new Action <IExposureNotificationEventCallback>(callback => { callback.OnPreauthorizeAllowed(); }), _ => new Action <IExposureNotificationEventCallback>(callback => { /* do nothing */ }), }; PageUtilities.InvokeViewAndViewModelAction(PageUtilities.GetCurrentPage(AppInstance.MainPage), action); }
//no se puede mandar a llamar MainPage ya que uso PRISM!!! private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e) { if (sender == null || e == null) { return; } var seleccionado = e.SelectedItem as MasterMenuItem; MainPage Root = Application.Current.MainPage as MainPage; var pagethis = PageUtilities.GetCurrentPage(Application.Current.MainPage); try { MainPage mainpageprueba = (MainPage)PageUtilities.GetCurrentPage(Application.Current.MainPage); mainpageprueba.ChangedDetailPage(seleccionado); } catch (Exception) { } try { Root.ChangedDetailPage(seleccionado); } catch (Exception) { } ((ListView)sender).SelectedItem = null; }
/// <summary> /// Called when the Activity has detected the user's press of the back key /// </summary> public static async Task <IBackPressedResult> OnBackPressed(Activity activity = null) { await semaphore.WaitAsync(); try { var container = ContainerLocator.Container; var appProvider = container.Resolve <IApplicationProvider>(); Page topPage = PageUtilities.GetCurrentPage(appProvider.MainPage); if (topPage is IDialogContainer dc) { var result = await dc.RequestCloseAsync(); return(result.Exception switch { DialogException de when de.Message == DialogException.CanCloseIsFalse => new BackPressedResult(), _ => new BackPressedResult { Success = result.Exception is null, Exception = result.Exception } }); }
private INavigationService GetCurrentNavigationService() { var topPage = PageUtilities.GetCurrentPage(Application.Current.MainPage); var topPageNavigationService = (topPage?.BindingContext as BaseViewModel)?.NavigationServicePublic; return(topPageNavigationService ?? _topMostNavigationService); }
protected override void OnSleep() { if (MainPage != null) { var page = PageUtilities.GetCurrentPage(MainPage); PageUtilities.InvokeViewAndViewModelAction <IApplicationLifecycleAware>(page, x => x.OnSleep()); } }
public static async Task <INavigationResult> GoBackToRootInvokeCurrentPageOnNavigatedToInternal(INavigationParameters parameters) { _logger?.Log(); var result = new NavigationResult(); try { if (parameters == null) { parameters = new NavigationParameters(); } ((INavigationParametersInternal)parameters).Add("__NavigationMode", NavigationMode.Back); // __NavigationMode is hardcode of Prism.Navigation.KnownInternalParameters.NavigationMode Page page = PageUtilities.GetCurrentPage(Application.Current.MainPage); var canNavigate = await PageUtilities.CanNavigateAsync(page, parameters); if (!canNavigate) { result.Exception = new NavigationException(NavigationException.IConfirmNavigationReturnedFalse, page); 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 await page.Navigation.PopToRootAsync(); foreach (var destroyPage in pagesToDestroy) { PageUtilities.OnNavigatedFrom(destroyPage, parameters); PageUtilities.DestroyPage(destroyPage); } Page currentPage = PageUtilities.GetCurrentPage(root); PageUtilities.OnNavigatedTo(currentPage, parameters); result.Success = true; return(result); } catch (Exception ex) { result.Exception = ex; return(result); } }
private INavigationService GetNavigationService() { if (PrismApplicationBase.Current is null) { return(null); } var navService = Container.Resolve <INavigationService>(PrismApplicationBase.NavigationServiceName); if (navService is IPageAware pa) { pa.Page = PageUtilities.GetCurrentPage(ApplicationProvider.MainPage); } return(navService); }
private INavigationService GetNavigationService() { if (PrismApplicationBase.Current is null) { return(null); } IContainerProvider container = Container; var navService = container.IsRegistered <INavigationService>(NavigationServiceName) ? container.Resolve <INavigationService>(NavigationServiceName) : container.Resolve <INavigationService>(); if (navService is IPageAware pa) { pa.Page = PageUtilities.GetCurrentPage(ApplicationProvider.MainPage); } return(navService); }
protected override async Task DoPush(Page currentPage, Page page, bool?useModalNavigation, bool animated, bool insertBeforeLast = false, int navigationOffset = 0) { switch (page) { case PopupPage popup: await _popupNavigation.PushAsync(popup, animated); break; default: if (_popupNavigation.PopupStack.Any()) { await _popupNavigation.PopAllAsync(animated); currentPage = PageUtilities.GetCurrentPage(_applicationProvider.MainPage); } await base.DoPush(currentPage, page, useModalNavigation, animated, insertBeforeLast, navigationOffset); break; } }
protected override void OnResume() { var page = PageUtilities.GetCurrentPage(MainPage); PageUtilities.InvokeViewAndViewModelAction <AppModel.IApplicationLifecycle>(page, x => x.OnResume()); }
public static async Task <INavigationResult> GoBackToTargetInternal <T>(INavigationParameters parameters) { _logger?.Log(); var result = new NavigationResult(); try { if (parameters == null) { parameters = new NavigationParameters(); } ((INavigationParametersInternal)parameters).Add("__NavigationMode", NavigationMode.Back); // __NavigationMode is hardcode of Prism.Navigation.KnownInternalParameters.NavigationMode var currentPage = PageUtilities.GetCurrentPage(Application.Current.MainPage); NavigationPage navigationPage = null; var tmp = currentPage; while (tmp.Parent != null) { if (tmp.Parent is NavigationPage) { navigationPage = tmp.Parent as NavigationPage; break; } else { tmp = tmp.Parent as Page; } } if (navigationPage == null) { result.Exception = new NavigationException("Require NavigationPage", currentPage); return(result); } var canNavigate = await PageUtilities.CanNavigateAsync(currentPage, parameters); if (!canNavigate) { result.Exception = new NavigationException(NavigationException.IConfirmNavigationReturnedFalse, currentPage); return(result); } // Cache the stack to avoid mutation. var stack = currentPage.Navigation.NavigationStack.ToList(); Page root = navigationPage.RootPage; // Initial root value. var pagesToDestroy = new List <Page>(); // For stack, A > B > C > D. We want to navigate from D to B. // A > B > D. // The remove order is D > C. for (int i = stack.Count - 1; i >= 1; i--) // i = 0 is root page. we don't remove it. { var page = stack[i]; if (page.BindingContext.GetType() == typeof(T)) // Assume target key is ViewModel's name. { root = page; // Root is B. break; } pagesToDestroy.Add(page); } // Temporary remove prism navigation aware var systemGoBackBehavior = navigationPage.Behaviors.FirstOrDefault(p => p is NavigationPageSystemGoBackBehavior); if (systemGoBackBehavior != null) { navigationPage.Behaviors.Remove(systemGoBackBehavior); } for (int i = 1; i < pagesToDestroy.Count; i++) // Skip page D, remove page C, { currentPage.Navigation.RemovePage(pagesToDestroy[i]); } await currentPage.Navigation.PopAsync(); // Navigate from D to B. foreach (var destroyPage in pagesToDestroy) // D, C OnNavigatedFrom and Destroy { PageUtilities.OnNavigatedFrom(destroyPage, parameters); PageUtilities.DestroyPage(destroyPage); } PageUtilities.OnNavigatedTo(root, parameters); // B OnNavigatedTo // Re-add prism navigation aware if (systemGoBackBehavior != null) { navigationPage.Behaviors.Add(systemGoBackBehavior); } result.Success = true; return(result); } catch (Exception ex) { result.Exception = ex; return(result); } }