// *** Protected Methods ***

        protected void OnFlyoutClosed(object sender, object e)
        {
            // Remove all navigation entries from the stack
            // TODO : Add some way to indicate to VMs that they are closing - IClosingAware?

            NavigationStack.Clear();
        }
        public void CanGoBack_IsTrueIfOnePageNavigated()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));

            Assert.Equal(true, navigationStack.CanGoBack);
        }
        public void CanGoBack_IsFalseIfOnePageNavigatedThenBack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.GoBack();

            Assert.Equal(false, navigationStack.CanGoBack);
        }
        public void Clear_TwoPagesNavigatedThenClear_CountIsZero()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));
            navigationStack.Clear();

            Assert.Equal(0, navigationStack.Count);
        }
        public void Clear_TwoPagesNavigatedThenClear_CurrentPageIsNull()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));
            navigationStack.Clear();

            Assert.Equal(null, navigationStack.CurrentPage);
        }
        // *** Methods ***

        public async Task <bool> RestoreNavigationStack()
        {
            // Retrieve a navigation stack from storage unless,
            //    (1) The NavigationStorageType is 'None'
            //    (2) Cannot find the navigation stack in storage

            NavigationManagerState restoredState = null;

            switch (NavigationStorageType)
            {
            case Navigation.NavigationStorageType.Local:
                restoredState = await storageManager.RetrieveAsync <NavigationManagerState>(ApplicationData.Current.LocalFolder, STORAGE_FILENAME);

                break;

            case Navigation.NavigationStorageType.Roaming:
                restoredState = await storageManager.RetrieveAsync <NavigationManagerState>(ApplicationData.Current.RoamingFolder, STORAGE_FILENAME);

                break;
            }

            // If a navigation stack is available, then restore this

            if (restoredState != null)
            {
                foreach (NavigationEntryState entryState in restoredState.NavigationStack.Reverse())
                {
                    // Push the restored navigation entry onto the stack

                    NavigationStack.Push(new NavigationEntry(entryState.PageName, entryState.ArgumentsData, entryState.StateData));
                }

                // Display the last page in the stack

                DisplayNavigationEntry(CurrentPage);

                // Call NavigatedTo() on the restored page

                CallNavigatedTo(CurrentPage, NavigationMode.Refresh);

                // Return true to signal success

                return(true);
            }

            // Otherwise navigate to the home page and return false

            else
            {
                NavigateTo(HomePageName);

                return(false);
            }
        }
        protected void OnSettingsFlyoutUnloaded(object sender, object e)
        {
            // Raise the FlyoutClosed event

            OnFlyoutClosed();

            // Remove all navigation entries from the stack
            // NB: Set the 'isUnloading' flag to stop reopening the system settings pane
            // TODO : Add some way to indicate to VMs that they are closing - IClosingAware?

            _isUnloading = true;
            NavigationStack.Clear();
            _isUnloading = false;
        }
Exemple #8
0
        // *** Methods ***

        public void GoBack()
        {
            // Check that we can go back

            if (!CanGoBack)
            {
                throw new InvalidOperationException(ResourceHelper.GetErrorResource("Exception_InvalidOperation_CannotGoBackWithEmptyBackStack"));
            }

            // Pop the last page from the stack, call NavigationFrom() and dispose any cached items

            INavigationEntry oldNavigationEntry = NavigationStack.Pop();

            CallNavigatingFrom(oldNavigationEntry, NavigationMode.Back);

            if (oldNavigationEntry is NavigationEntry)
            {
                ((NavigationEntry)oldNavigationEntry).DisposeCachedItems();
            }

            // Display the new current page from the navigation stack

            DisplayNavigationEntry(CurrentNavigationEntry);

            // If the value of CanGoBack has changed then raise an event
            // NB: We can assume that the old value was true otherwise an exception is thrown on entry to this method

            if (!CanGoBack)
            {
                OnCanGoBackChanged();
            }

            // Call NavigatingTo()

            CallNavigatedTo(CurrentNavigationEntry, NavigationMode.Back);
        }
        public void NavigatingFrom_IsNotCalledWhenNoPagesArePushedOntoTheStack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            List<PageNavigationEventArgs> navigationEvents = new List<PageNavigationEventArgs>();
            navigationStack.NavigatingFrom += delegate (object sender, PageNavigationEventArgs e) { navigationEvents.Add(e); };

            navigationStack.Push(new PageInfo[]
                    {
                    });

            Assert.Equal(0, navigationEvents.Count);
        }
        public void Push_AddsSpecifiedPages()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.Push(new[]
                    {
                        new PageInfo("Page 1", null),
                        new PageInfo("Page 2", null)
                    });

            Assert.Equal("Page 1", navigationStack[0].PageName);
            Assert.Equal("Page 2", navigationStack[1].PageName);
        }
        public void Push_OntoEmptyStack_ReplacesStack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.Push(new[]
                    {
                        new PageInfo("Page 1", null),
                        new PageInfo("Page 2", null)
                    });

            Assert.Equal(2, navigationStack.Count);
        }
        public void PropertyChanged_CanGoBack_IsNotCalledWhenEmptyNavigationStackIsCleared()
        {
            NavigationStack navigationStack = new NavigationStack();

            int changedCount = 0;
            navigationStack.PropertyChanged += delegate (object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "CanGoBack") changedCount++; };

            navigationStack.Clear();

            Assert.Equal(0, changedCount);
        }
        public void NavigateTo_ThrowsException_NullPage()
        {
            NavigationStack navigationStack = new NavigationStack();

            var e = Assert.Throws<ArgumentNullException>(() => navigationStack.NavigateTo(null));

            Assert.Equal("Value cannot be null.\r\nParameter name: page", e.Message);
            Assert.Equal("page", e.ParamName);
        }
        public void PageDisposed_IsNotCalledWhenNavigatingToANewPage()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));

            List<PageNavigationEventArgs> pageDisposedEvents = new List<PageNavigationEventArgs>();
            navigationStack.PageDisposed += delegate (object sender, PageNavigationEventArgs e) { pageDisposedEvents.Add(e); };

            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            Assert.Equal(0, pageDisposedEvents.Count);
        }
        public void PropertyChanged_CanGoBack_IsNotCalledWheNavigatingBackToFirstPage()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));
            navigationStack.NavigateTo(new PageInfo("Page 3", null));

            int changedCount = 0;
            navigationStack.PropertyChanged += delegate (object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "CanGoBack") changedCount++; };

            navigationStack.GoBackTo(navigationStack[0]);

            Assert.Equal(0, changedCount);
        }
        public void CollectionChanged_IsCalledWhenPagesArePushedOntoStack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            List<NotifyCollectionChangedEventArgs> changeEvents = new List<NotifyCollectionChangedEventArgs>();
            navigationStack.CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) { changeEvents.Add(e); };

            navigationStack.Push(new[]
                    {
                        new PageInfo("Page 3", null),
                        new PageInfo("Page 4", null)
                    });

            Assert.Equal(1, changeEvents.Count);
            NotifyCollectionChangedEventArgs changeEvent = changeEvents[0];
            Assert.Equal(NotifyCollectionChangedAction.Add, changeEvent.Action);
            Assert.Equal(2, changeEvent.NewItems.Count);
            Assert.Equal("Page 3", ((PageInfo)changeEvent.NewItems[0]).PageName);
            Assert.Equal("Page 4", ((PageInfo)changeEvent.NewItems[1]).PageName);
            Assert.Equal(2, changeEvent.NewStartingIndex);
        }
        public void CollectionChanged_IsNotCalledWhenNoPagesArePushedOntoStack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            List<NotifyCollectionChangedEventArgs> changeEvents = new List<NotifyCollectionChangedEventArgs>();
            navigationStack.CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) { changeEvents.Add(e); };

            navigationStack.Push(new PageInfo[]
                    {
                    });

            Assert.Equal(0, changeEvents.Count);
        }
        public void CollectionChanged_IsCalledWhenNavigatingBackTo_OnPage()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));
            navigationStack.NavigateTo(new PageInfo("Page 3", null));

            List<NotifyCollectionChangedEventArgs> changeEvents = new List<NotifyCollectionChangedEventArgs>();
            navigationStack.CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) { changeEvents.Add(e); };

            navigationStack.GoBackTo(navigationStack[1]);

            Assert.Equal(1, changeEvents.Count);
            NotifyCollectionChangedEventArgs changeEvent = changeEvents[0];
            Assert.Equal(NotifyCollectionChangedAction.Remove, changeEvent.Action);
            Assert.Equal(1, changeEvent.OldItems.Count);
            Assert.Equal("Page 3", ((PageInfo)changeEvent.OldItems[0]).PageName);
            Assert.Equal(2, changeEvent.OldStartingIndex);
        }
        public void CollectionChanged_IsCalledWhenNavigationStackIsCleared()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            List<NotifyCollectionChangedEventArgs> changeEvents = new List<NotifyCollectionChangedEventArgs>();
            navigationStack.CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) { changeEvents.Add(e); };

            navigationStack.Clear();

            Assert.Equal(1, changeEvents.Count);
            NotifyCollectionChangedEventArgs changeEvent = changeEvents[0];
            Assert.Equal(NotifyCollectionChangedAction.Reset, changeEvent.Action);
        }
        public void Count_IsInitiallyZero()
        {
            NavigationStack navigationStack = new NavigationStack();

            Assert.Equal(0, navigationStack.Count);
        }
        public void Push_ThrowsException_NullPageInEnumerable()
        {
            NavigationStack navigationStack = new NavigationStack();
            PageInfo page1 = new PageInfo("Page 1", null);
            PageInfo page3 = new PageInfo("Page 1", null);

            var e = Assert.Throws<ArgumentException>(() =>
            {
                navigationStack.Push(new PageInfo[] { page1, null, page3 });
            });

            Assert.Equal("The list of pages cannot contain a 'null' page.\r\nParameter name: pages", e.Message);
            Assert.Equal("pages", e.ParamName);
        }
        public void Push_ThrowsException_NullPages()
        {
            NavigationStack navigationStack = new NavigationStack();

            var e = Assert.Throws<ArgumentNullException>(() =>
            {
                navigationStack.Push(null);
            });

            Assert.Equal("Value cannot be null.\r\nParameter name: pages", e.Message);
            Assert.Equal("pages", e.ParamName);
        }
        public void PageDisposed_IsCalledWhenGoingBack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            List<PageNavigationEventArgs> pageDisposedEvents = new List<PageNavigationEventArgs>();
            navigationStack.PageDisposed += delegate (object sender, PageNavigationEventArgs e) { pageDisposedEvents.Add(e); };

            navigationStack.GoBack();

            Assert.Equal(1, pageDisposedEvents.Count);
            PageNavigationEventArgs pageDisposedEvent = pageDisposedEvents[0];
            Assert.Equal(PageNavigationMode.Back, pageDisposedEvent.NavigationMode);
            Assert.Equal("Page 2", pageDisposedEvent.Page.PageName);
        }
        public void Push_EmptyCollection_DoesNotChangeStack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            navigationStack.Push(new PageInfo[]
                    {
                    });

            Assert.Equal(2, navigationStack.Count);
        }
        public void PageDisposed_IsCalledWhenNavigatingBackMultiplePages()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));
            navigationStack.NavigateTo(new PageInfo("Page 3", null));

            List<PageNavigationEventArgs> pageDisposedEvents = new List<PageNavigationEventArgs>();
            navigationStack.PageDisposed += delegate (object sender, PageNavigationEventArgs e) { pageDisposedEvents.Add(e); };

            navigationStack.GoBackTo(navigationStack[0]);

            Assert.Equal(2, pageDisposedEvents.Count);
            PageNavigationEventArgs pageDisposedEventPage2 = pageDisposedEvents.First(e => e.Page.PageName == "Page 2");
            PageNavigationEventArgs pageDisposedEventPage3 = pageDisposedEvents.First(e => e.Page.PageName == "Page 3");
            Assert.Equal(PageNavigationMode.Back, pageDisposedEventPage2.NavigationMode);
            Assert.Equal("Page 2", pageDisposedEventPage2.Page.PageName);
            Assert.Equal(PageNavigationMode.Back, pageDisposedEventPage3.NavigationMode);
            Assert.Equal("Page 3", pageDisposedEventPage3.Page.PageName);
        }
        public void NavigatedTo_IsNotCalledWhenFirstPageNavigatedThenBack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));

            List<PageNavigationEventArgs> navigationEvents = new List<PageNavigationEventArgs>();
            navigationStack.NavigatedTo += delegate (object sender, PageNavigationEventArgs e) { navigationEvents.Add(e); };

            navigationStack.GoBack();

            Assert.Equal(0, navigationEvents.Count);
        }
        public void GetEnumerator_Generic_EnumeratesPagesInStack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            IEnumerable<PageInfo> pages = (IEnumerable<PageInfo>)navigationStack;
            string[] pageNames = pages.Select(entry => entry.PageName).ToArray();

            Assert.Equal(new string[] { "Page 1", "Page 2" }, pageNames);
        }
        public void NavigatedTo_IsCalledWhenPagesArePushedOntoStack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            List<PageNavigationEventArgs> navigationEvents = new List<PageNavigationEventArgs>();
            navigationStack.NavigatedTo += delegate (object sender, PageNavigationEventArgs e) { navigationEvents.Add(e); };

            navigationStack.Push(new[]
                    {
                        new PageInfo("Page 3", null),
                        new PageInfo("Page 4", null)
                    });

            Assert.Equal(1, navigationEvents.Count);
            PageNavigationEventArgs navigationEvent = navigationEvents[0];
            Assert.Equal(PageNavigationMode.New, navigationEvent.NavigationMode);
            Assert.Equal("Page 4", navigationEvent.Page.PageName);
        }
        public void PropertyChanged_CanGoBack_IsCalledWhenNavigationStackIsCleared()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));

            int changedCount = 0;
            navigationStack.PropertyChanged += delegate (object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "CanGoBack") changedCount++; };

            navigationStack.Clear();

            Assert.Equal(1, changedCount);
        }
        public void Push_OntoExistingStack_AddsToEndOfStack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            navigationStack.Push(new[]
                    {
                        new PageInfo("Page 1", null),
                        new PageInfo("Page 2", null)
                    });

            Assert.Equal(4, navigationStack.Count);
        }
        public void PropertyChanged_CanGoBack_IsNotCalledWhenItemsArePushedOntoExistingStack()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));

            int changedCount = 0;
            navigationStack.PropertyChanged += delegate (object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "CanGoBack") changedCount++; };

            navigationStack.Push(new[]
                    {
                        new PageInfo("Page 3", null),
                        new PageInfo("Page 4", null)
                    });

            Assert.Equal(0, changedCount);
        }
        public void NavigatingFrom_IsCalledWhenNavigatingBackToAPage()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));
            navigationStack.NavigateTo(new PageInfo("Page 3", null));

            List<PageNavigationEventArgs> navigationEvents = new List<PageNavigationEventArgs>();
            navigationStack.NavigatingFrom += delegate (object sender, PageNavigationEventArgs e) { navigationEvents.Add(e); };

            navigationStack.GoBackTo(navigationStack[0]);

            Assert.Equal(1, navigationEvents.Count);
            PageNavigationEventArgs navigationEvent = navigationEvents[0];
            Assert.Equal(PageNavigationMode.Back, navigationEvent.NavigationMode);
            Assert.Equal("Page 3", navigationEvent.Page.PageName);
        }
        public void CurrentPage_IsInitiallyNull()
        {
            NavigationStack navigationStack = new NavigationStack();

            Assert.Equal(null, navigationStack.CurrentPage);
        }
        public void Push_WhenEmptyPagesPushed_CurrentPageIsLastPage()
        {
            NavigationStack navigationStack = new NavigationStack();

            navigationStack.NavigateTo(new PageInfo("Page 1", null));
            navigationStack.NavigateTo(new PageInfo("Page 2", null));

            navigationStack.Push(new PageInfo[]
                    {
                    });

            Assert.Equal("Page 2", navigationStack.CurrentPage.PageName);
        }