Esempio n. 1
0
        protected virtual void OnPopViewModel(IPageViewModel viewModel, bool animated)
        {
            if (PageReferences.LastOrDefault()?.Model != viewModel)
            {
                throw new Exception(String.Format("The viewModel is not the last in the stack: {0}", viewModel));
            }

            var pageReference = PageReferences.LastOrDefault();

            PageReferences.RemoveAt(PageReferences.Count - 1);
            if (this.Navigation.NavigationStack.LastOrDefault() == pageReference.View)
            {
                PopAsync();
            }
        }
Esempio n. 2
0
        void _pages_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            bool wasResetting = resetting;

            resetting = false;

            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                if (wasResetting && e.NewItems.OfType <IPageViewModel> ().FirstOrDefault() == PageReferences.FirstOrDefault()?.Model)
                {
                    OnPopToRoot(Pages.LastOrDefault(), TransitionAnimationEnabled);
                }
                else if (wasResetting)
                {
                    OnPopToNewRoot(e.NewItems.OfType <IPageViewModel> ().LastOrDefault(), TransitionAnimationEnabled);
                }
                else
                {
                    OnPushViewModel(e.NewItems.OfType <IPageViewModel> ().LastOrDefault(), TransitionAnimationEnabled);
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                if (PageReferences.LastOrDefault()?.Model == e.OldItems.OfType <IPageViewModel> ().LastOrDefault() && e.OldItems.Count == 1)
                {
                    OnPopViewModel(e.OldItems.OfType <IPageViewModel> ().LastOrDefault(), TransitionAnimationEnabled);
                }
                else
                {
                    PageReferences.RemoveAll(r => e.OldItems.Contains(r.Model));
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                resetting = true;
            }
        }
Esempio n. 3
0
        async void updatePages()
        {
            if (_pages != null && _pages.Count > 0)
            {
                foreach (var pref in PageReferences.Where(p => !_pages.Contains(p.Model)).ToList())
                {
                    PageReferences.Remove(pref);
                }

                if (new[] { this.Navigation.NavigationStack.FirstOrDefault(), this.Navigation.NavigationStack.LastOrDefault(), PageReferences.LastOrDefault()?.View }
                    .All(v => v == PageReferences.FirstOrDefault()?.View))
                {
                    OnPopToRoot(Pages.LastOrDefault(), TransitionAnimationEnabled);
                }
                else
                {
                    if (Navigation.NavigationStack.Count > 0)
                    {
                        var pref = createPageFor(Pages.LastOrDefault());

                        PageReferences.Clear();
                        PageReferences.Add(pref);
                        await popToNewRootAsync(pref.View, TransitionAnimationEnabled);
                    }
                    else
                    {
                        OnPushViewModel(Pages.LastOrDefault(), TransitionAnimationEnabled);
                    }
                }
            }
            else
            {
                //At least on page should be displayed
                PageReferences.Clear();
                var blankPage = new ContentPage {
                    BackgroundColor = Color.Transparent
                };

                if (Navigation.NavigationStack.Count > 0)
                {
                    await popToNewRootAsync(blankPage, TransitionAnimationEnabled);
                }
                else
                {
                    await PushAsync(blankPage, TransitionAnimationEnabled);
                }
            }
        }