public void CleanNavigationStack() { while (_rootFrame.BackStack.Any()) { _rootFrame.RemoveBackEntry(); } }
public void RemoveBackEntry() { if (EnsureMainFrame() && _mainFrame.CanGoBack) { _mainFrame.RemoveBackEntry(); } }
public void NavigateTo(Uri pageUri, bool oneWay) { if (EnsureMainFrame()) { _mainFrame.Dispatcher.BeginInvoke(delegate { _mainFrame.Navigate(pageUri); _mainFrame.RemoveBackEntry(); }); } }
public void RemoveBackEntries() { if (EnsureMainFrame() && _mainFrame.CanGoBack) { while (_mainFrame.BackStack.Count() > 0) { _mainFrame.RemoveBackEntry(); } } }
protected override void OnBackKeyPress(CancelEventArgs e) { PhoneApplicationFrame RootFrame = Application.Current.RootVisual as PhoneApplicationFrame; if (RootFrame != null) { if (RootFrame.BackStack.Count() > 0) { RootFrame.RemoveBackEntry(); RootFrame.RemoveBackEntry(); } } }
private void OnFrameNavigated(object sender, EventArgs e) { this.isNavigatingNow = false; if (!string.IsNullOrEmpty(this.navigationPageSource)) { int index = 0; var navigatedItem = rootFame.BackStack.SingleOrDefault(item => item.Source.OriginalString.Contains(navigationPageSource)); if (navigatedItem != null) { index = rootFame.BackStack.ToList().IndexOf(navigatedItem); } else { var homePageSource = rootFame.BackStack.SingleOrDefault(item => item.Source.OriginalString.Contains("/Views/Home/HomePage.xaml")); index = rootFame.BackStack.ToList().IndexOf(homePageSource) - 1; } while (index >= 0) { rootFame.RemoveBackEntry(); index--; } this.navigationPageSource = null; } }
public void ClearNavigationHistory() { PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame; while (rootFrame.RemoveBackEntry() != null) { ; } }
public void RemoveBackEntry() { if (_mainFrame.BackStack != null && _mainFrame.BackStack.Any()) { DispatcherHelper.UIDispatcher.BeginInvoke(() => { _mainFrame.RemoveBackEntry(); }); } }
public static System.Windows.Navigation.JournalEntry RemoveBackEntry() { PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; if (frame == null) { return(null); } return(frame.RemoveBackEntry()); }
public async Task Navigate(CancellationToken ct, INavigationRequest request) { await _innerRequestNavigation.Navigate(ct, request); var firstEntry = _applicationFrame.BackStack.FirstOrDefault(); if (firstEntry != null && firstEntry.Source.Equals(_entryPointUri)) { await _dispatcherScheduler.Run(() => _applicationFrame.RemoveBackEntry()); } }
/// <summary> /// Purges the Root Frame off all Navigational Journal Entries. This /// has the effect of causing you app to exit if the back button is /// pressed after this method is called. /// </summary> /// <param name="rootFrame"></param> public static void PurgeNavigationalBackstack(PhoneApplicationFrame rootFrame) { var purgeList = new System.Collections.Generic.List<System.Windows.Navigation.JournalEntry>(); foreach (var entry in rootFrame.BackStack) purgeList.Add(entry); foreach (var entry in purgeList) { if (rootFrame.CanGoBack) rootFrame.RemoveBackEntry(); } }
private async Task NavigateBackWithNotAliveRequest(CancellationToken ct, INavigationHistoryEntry previousEntry) { //entries has no navigation page created so we navigate to the page and remove var last = _history.Entries.Last(); await Navigate(ct, previousEntry.Request); await _dispatcherScheduler.Run(() => _frame.RemoveBackEntry()); //removes the previous entry which was not alive await _history.Remove(ct, previousEntry); //removes the last entry which was the page where the back navigation was made await _history.Remove(ct, last); }
private void ClearBackStack() { int entriesToRemove = _rootFrame.BackStack.Count(); for (int i = 0; i < entriesToRemove; i++) { // Not at the right page yet, removes the entry. _rootFrame.RemoveBackEntry(); } }
private void ClearBackStackAfterReset(object sender, NavigationEventArgs e) { // 取消注册事件,以便不再调用该事件 RootFrame.Navigated -= ClearBackStackAfterReset; // 只为“新建”(向前)和“刷新”导航清除堆栈 if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh) { return; } // 为了获得 UI 一致性,请清除整个页面堆栈 while (RootFrame.RemoveBackEntry() != null) { ; // 不执行任何操作 } }
private void ClearBackStackAfterReset(object sender, NavigationEventArgs e) { // Unregister the event so it doesn't get called again RootFrame.Navigated -= ClearBackStackAfterReset; // Only clear the stack for 'new' (forward) and 'refresh' navigations if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh) { return; } // For UI consistency, clear the entire page stack while (RootFrame.RemoveBackEntry() != null) { ; // do nothing } }
protected AutoSuspendApplication() { var host = new SuspensionHost(); host.IsLaunchingNew = Observable.FromEventPattern <LaunchingEventArgs>( x => PhoneApplicationService.Current.Launching += x, x => PhoneApplicationService.Current.Launching -= x) .Select(_ => Unit.Default); host.IsUnpausing = Observable.FromEventPattern <ActivatedEventArgs>( x => PhoneApplicationService.Current.Activated += x, x => PhoneApplicationService.Current.Activated -= x) .Where(x => x.EventArgs.IsApplicationInstancePreserved) .Select(_ => Unit.Default); // NB: "Applications should not perform resource-intensive tasks // such as loading from isolated storage or a network resource // during the Activated event handler because it increase the time // it takes for the application to resume" host.IsResuming = Observable.FromEventPattern <ActivatedEventArgs>( x => PhoneApplicationService.Current.Activated += x, x => PhoneApplicationService.Current.Activated -= x) .Where(x => !x.EventArgs.IsApplicationInstancePreserved) .Select(_ => Unit.Default) .ObserveOn(RxApp.TaskpoolScheduler); // NB: No way to tell OS that we need time to suspend, we have to // do it in-process host.ShouldPersistState = Observable.Merge( Observable.FromEventPattern <DeactivatedEventArgs>( x => PhoneApplicationService.Current.Deactivated += x, x => PhoneApplicationService.Current.Deactivated -= x) .Select(_ => Disposable.Empty), Observable.FromEventPattern <ClosingEventArgs>( x => PhoneApplicationService.Current.Closing += x, x => PhoneApplicationService.Current.Closing -= x) .Select(_ => Disposable.Empty)); host.ShouldInvalidateState = Observable.FromEventPattern <ApplicationUnhandledExceptionEventArgs>(x => UnhandledException += x, x => UnhandledException -= x) .Select(_ => Unit.Default); SuspensionHost = host; // // Do the equivalent steps that the boilerplate code does for WP8 apps // if (RootFrame != null) { return; } RootFrame = new PhoneApplicationFrame(); var currentBackHook = default(IDisposable); var currentViewFor = default(WeakReference <IViewFor>); RootFrame.Navigated += (o, e) => { // Always clear the WP8 Back Stack, we're using our own while (RootFrame.RemoveBackEntry() != null) { } if (currentBackHook != null) { currentBackHook.Dispose(); } var page = RootFrame.Content as PhoneApplicationPage; if (page != null) { currentBackHook = Observable.FromEventPattern <CancelEventArgs>(x => page.BackKeyPress += x, x => page.BackKeyPress -= x) .Where(_ => ViewModel != null) .Subscribe(x => { if (!ViewModel.Router.NavigateBack.CanExecute(null)) { return; } x.EventArgs.Cancel = true; ViewModel.Router.NavigateBack.Execute(null); }); var viewFor = page as IViewFor; if (viewFor == null) { throw new Exception("Your Main Page (i.e. the one that is pointed to by WMAppManifest) must implement IViewFor<YourAppBootstrapperClass>"); } currentViewFor = new WeakReference <IViewFor>(viewFor); viewFor.ViewModel = ViewModel; } // Finally make it live RootVisual = RootFrame; }; _viewModelChanged.StartWith(ViewModel).Where(x => x != null).Subscribe(vm => { var viewFor = default(IViewFor); if (currentViewFor != null && currentViewFor.TryGetTarget(out viewFor)) { viewFor.ViewModel = vm; } }); UnhandledException += (o, e) => { if (Debugger.IsAttached) { Debugger.Break(); } }; RootFrame.NavigationFailed += (o, e) => { if (Debugger.IsAttached) { Debugger.Break(); } }; }
/// <summary> /// Removes an entry from the navigation back stack /// </summary> public void RemoveBackEntry() { _frame.RemoveBackEntry(); }
/// <summary> /// Naviguer vers un ViewModel /// </summary> /// <typeparam name="TTo"> /// Type du Viewmodel vers lequel la navigation est effectuée /// </typeparam> /// <param name="viewModelToName"> /// Type du Viewmodel vers lequel la navigation est effectuée /// </param> /// <param name="viewModelFromName"> /// Type du Viewmodel depuis lequel la navigation est effectuée /// </param> /// <param name="parametersViewModel"> /// Tableau des paramétres éventuels à transmettre au constructeur du ViewModel /// </param> /// <param name="functionToLoad"> /// Permet de spécifier un nom de fonction à appeler aprés le chargement du viewModel ciblé /// </param> /// <param name="parametersFunction"> /// Paramétres pour la fonction appelée /// </param> /// <param name="newInstance"> /// Indique si l'on génére une nouvelle instance obligatoirement /// </param> /// <returns> /// Retourne la clé unique pour SimpleIoc, de l'instance du viewmodel vers lequel la navigation a eu lieu /// </returns> private string Navigate <TTo>(Type viewModelToName, Type viewModelFromName, object[] parametersViewModel, string functionToLoad, object[] parametersFunction, bool newInstance = false) where TTo : class { try { //Pré-navigation if (PreviewNavigate != null) { ViewModelBase currentInstance = null; if (viewModelFromName != null) { if (_factoriesInstances.ContainsKey(viewModelToName)) { string keyInstance; if (_factoriesInstances.TryGetValue(viewModelToName, out keyInstance)) { currentInstance = (ViewModelBase)SimpleIoc.Default.GetInstance(viewModelToName, keyInstance); } } } if (!PreviewNavigate(currentInstance, viewModelFromName, viewModelToName)) { if (NavigationCanceledOnPreviewNavigate != null) { NavigationCanceledOnPreviewNavigate(this, EventArgs.Empty); } return(string.Empty); } } //Vérification du type de ViewModel demandé pour l'historique if (!viewModelToName.GetTypeInfo().IsSubclassOf(typeof(ViewModelBase))) { throw new ViewModelHistoryTypeException(viewModelToName.ToString()); } //Gestion de l'historique if (viewModelFromName != null) { if (_historyInstances.ContainsKey(viewModelToName)) { _historyInstances[viewModelToName] = viewModelFromName; } else { _historyInstances.Add(viewModelToName, viewModelFromName); } //Gestion de l'historique de navigation SetNavigationHistory(viewModelFromName); } //Génération d'une instance du viewmodel string key; if (_factoriesInstances.ContainsKey(viewModelToName) && !newInstance) { _factoriesInstances.TryGetValue(viewModelToName, out key); } else { if (_factoriesInstances.ContainsKey(viewModelToName)) { //Suppression de l'instance du viewModel dans le cache de SimpleIOC _factoriesInstances.TryGetValue(viewModelToName, out key); if (key != null) { _factoriesInstances.Remove(viewModelToName); SimpleIoc.Default.Unregister <TTo>(key); } } var instanceNew = Activator.CreateInstance(viewModelToName, parametersViewModel); key = Guid.NewGuid().ToString(); SimpleIoc.Default.Register <TTo>(() => (TTo)instanceNew, key); _factoriesInstances.Add(viewModelToName, key); } var instance = (ViewModelBase)SimpleIoc.Default.GetInstance(viewModelToName, key); if (instance != null) { #if WINDOWS_PHONE System.Uri instanceToNavigate; #else Type instanceToNavigate; #endif var result = _viewsRegister.TryGetValue(instance.GetType(), out instanceToNavigate); if (result) { _currentViewModel = viewModelToName; SetCurrentView(instanceToNavigate); #if WINDOWS_PHONE //Suppression de l'entrée précédente si l'on ne doit pas naviguée dessus if (viewModelFromName == null) { try { if (_rootFrame != null) { _rootFrame.RemoveBackEntry(); } } catch (Exception) { } } #endif } } //Gestion d'une fonction à appeler suite à la génération de l'instance if (!string.IsNullOrEmpty(functionToLoad)) { var method = typeof(TTo).GetMethod(functionToLoad, parametersFunction); if (method != null) { method.Invoke(instance, parametersFunction); } else { var countParameters = parametersFunction != null ? ((IEnumerable <object>)parametersFunction).Count() : 0; throw new FunctionToLoadNavigationException(string.Format("{0} with {1} parameter(s)", functionToLoad, countParameters), typeof(TTo).Name); } } return(key); } catch (Exception e) { throw new NavigationException(e); } }
protected AutoSuspendApplication() { var host = new SuspensionHost(); host.IsLaunchingNew = Observable.FromEventPattern<LaunchingEventArgs>( x => PhoneApplicationService.Current.Launching += x, x => PhoneApplicationService.Current.Launching -= x) .Select(_ => Unit.Default); host.IsUnpausing = Observable.FromEventPattern<ActivatedEventArgs>( x => PhoneApplicationService.Current.Activated += x, x => PhoneApplicationService.Current.Activated -= x) .Where(x => x.EventArgs.IsApplicationInstancePreserved) .Select(_ => Unit.Default); // NB: "Applications should not perform resource-intensive tasks // such as loading from isolated storage or a network resource // during the Activated event handler because it increase the time // it takes for the application to resume" host.IsResuming = Observable.FromEventPattern<ActivatedEventArgs>( x => PhoneApplicationService.Current.Activated += x, x => PhoneApplicationService.Current.Activated -= x) .Where(x => !x.EventArgs.IsApplicationInstancePreserved) .Select(_ => Unit.Default) .ObserveOn(RxApp.TaskpoolScheduler); // NB: No way to tell OS that we need time to suspend, we have to // do it in-process host.ShouldPersistState = Observable.Merge( Observable.FromEventPattern<DeactivatedEventArgs>( x => PhoneApplicationService.Current.Deactivated += x, x => PhoneApplicationService.Current.Deactivated -= x) .Select(_ => Disposable.Empty), Observable.FromEventPattern<ClosingEventArgs>( x => PhoneApplicationService.Current.Closing += x, x => PhoneApplicationService.Current.Closing -= x) .Select(_ => Disposable.Empty)); host.ShouldInvalidateState = Observable.FromEventPattern<ApplicationUnhandledExceptionEventArgs>(x => UnhandledException += x, x => UnhandledException -= x) .Select(_ => Unit.Default); SuspensionHost = host; // // Do the equivalent steps that the boilerplate code does for WP8 apps // if (RootFrame != null) return; RootFrame = new PhoneApplicationFrame(); var currentBackHook = default(IDisposable); var currentViewFor = default(WeakReference<IViewFor>); RootFrame.Navigated += (o, e) => { // Always clear the WP8 Back Stack, we're using our own while (RootFrame.RemoveBackEntry() != null) {} if (currentBackHook != null) currentBackHook.Dispose(); var page = RootFrame.Content as PhoneApplicationPage; if (page != null) { currentBackHook = Observable.FromEventPattern<CancelEventArgs>(x => page.BackKeyPress += x, x => page.BackKeyPress -= x) .Where(_ => ViewModel != null) .Subscribe(x => { if (!ViewModel.Router.NavigateBack.CanExecute(null)) return; x.EventArgs.Cancel = true; ViewModel.Router.NavigateBack.Execute(null); }); var viewFor = page as IViewFor; if (viewFor == null) { throw new Exception("Your Main Page (i.e. the one that is pointed to by WMAppManifest) must implement IViewFor<YourAppBootstrapperClass>"); } currentViewFor = new WeakReference<IViewFor>(viewFor); viewFor.ViewModel = ViewModel; } // Finally make it live RootVisual = RootFrame; }; _viewModelChanged.StartWith(ViewModel).Where(x => x != null).Subscribe(vm => { var viewFor = default(IViewFor); if (currentViewFor != null && currentViewFor.TryGetTarget(out viewFor)) { viewFor.ViewModel = vm; } }); UnhandledException += (o, e) => { if (Debugger.IsAttached) Debugger.Break(); }; RootFrame.NavigationFailed += (o, e) => { if (Debugger.IsAttached) Debugger.Break(); }; }
public bool RequestRemoveBackStep() { return(InvokeOrBeginInvoke(() => _rootFrame.RemoveBackEntry())); }
public void RemoveBackEntry() { _phoneApplicationFrame.RemoveBackEntry(); }
protected override void RemoveBackEntry() { _service.RemoveBackEntry(); }
void _rootFrame_Loaded(object sender, RoutedEventArgs e) { _rootFrame.RemoveBackEntry(); }
public JournalEntry RemoveBackEntry() { return(_frame.RemoveBackEntry()); }
public bool RequestRemoveBackStep() { return(RequestMainThreadAction(() => _rootFrame.RemoveBackEntry())); }