コード例 #1
0
 public void CleanNavigationStack()
 {
     while (_rootFrame.BackStack.Any())
     {
         _rootFrame.RemoveBackEntry();
     }
 }
コード例 #2
0
 public void RemoveBackEntry()
 {
     if (EnsureMainFrame() && _mainFrame.CanGoBack)
     {
         _mainFrame.RemoveBackEntry();
     }
 }
コード例 #3
0
 public void NavigateTo(Uri pageUri, bool oneWay)
 {
     if (EnsureMainFrame())
     {
         _mainFrame.Dispatcher.BeginInvoke(delegate
         {
             _mainFrame.Navigate(pageUri);
             _mainFrame.RemoveBackEntry();
         });
     }
 }
コード例 #4
0
 public void RemoveBackEntries()
 {
     if (EnsureMainFrame() &&
         _mainFrame.CanGoBack)
     {
         while (_mainFrame.BackStack.Count() > 0)
         {
             _mainFrame.RemoveBackEntry();
         }
     }
 }
コード例 #5
0
        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();
                }
            }
        }
コード例 #6
0
        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;
            }
        }
コード例 #7
0
        public void ClearNavigationHistory()
        {
            PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;

            while (rootFrame.RemoveBackEntry() != null)
            {
                ;
            }
        }
コード例 #8
0
 public void RemoveBackEntry()
 {
     if (_mainFrame.BackStack != null && _mainFrame.BackStack.Any())
     {
         DispatcherHelper.UIDispatcher.BeginInvoke(() =>
         {
             _mainFrame.RemoveBackEntry();
         });
     }
 }
コード例 #9
0
ファイル: NavigationService.cs プロジェクト: pitetb/quizzapp
        public static System.Windows.Navigation.JournalEntry RemoveBackEntry()
        {
            PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;

            if (frame == null)
            {
                return(null);
            }

            return(frame.RemoveBackEntry());
        }
コード例 #10
0
        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());
            }
        }
コード例 #11
0
        /// <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();
            }
        }
コード例 #12
0
ファイル: PhoneNavigationService.cs プロジェクト: Galad/Hanno
        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);
        }
コード例 #13
0
            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();
                }
            }
コード例 #14
0
ファイル: App.xaml.cs プロジェクト: envyslee/dxDoc
        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)
            {
                ; // 不执行任何操作
            }
        }
コード例 #15
0
        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
            }
        }
コード例 #16
0
        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();
                }
            };
        }
コード例 #17
0
 /// <summary>
 /// Removes an entry from the navigation back stack
 /// </summary>
 public void RemoveBackEntry()
 {
     _frame.RemoveBackEntry();
 }
コード例 #18
0
ファイル: Navigation.cs プロジェクト: mplessis/navegar
        /// <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);
            }
        }
コード例 #19
0
        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();
            };
        }
コード例 #20
0
 public bool RequestRemoveBackStep()
 {
     return(InvokeOrBeginInvoke(() => _rootFrame.RemoveBackEntry()));
 }
コード例 #21
0
ファイル: NavigationService.cs プロジェクト: garapani/DDNews
 public void RemoveBackEntry()
 {
     _phoneApplicationFrame.RemoveBackEntry();
 }
コード例 #22
0
 protected override void RemoveBackEntry()
 {
     _service.RemoveBackEntry();
 }
コード例 #23
0
 void _rootFrame_Loaded(object sender, RoutedEventArgs e)
 {
     _rootFrame.RemoveBackEntry();
 }
コード例 #24
0
 public JournalEntry RemoveBackEntry()
 {
     return(_frame.RemoveBackEntry());
 }
コード例 #25
0
 public bool RequestRemoveBackStep()
 {
     return(RequestMainThreadAction(() => _rootFrame.RemoveBackEntry()));
 }