Exemplo n.º 1
0
        void nextPage_Clicked(object sender, EventArgs e)
        {
            ContentPage page = null;

            page = new ContentPage()
            {
                Title   = "second page",
                Content = new StackLayout()
                {
                    Children =
                    {
                        new Button()
                        {
                            Text    = "Toggle Back Button",
                            Command = new Command(() =>
                            {
                                NavigationPage.SetHasBackButton(page, !NavigationPage.GetHasBackButton(page));
                            })
                        },
                        new Button()
                        {
                            Text    = "Toggle Title View",
                            Command = new Command(() =>
                            {
                                changeTitleView_Clicked(page, EventArgs.Empty);
                            })
                        }
                    }
                }
            };

            NavigationPage.SetTitleView(page, createGrid());
            Navigation.PushAsync(page);
        }
        public override void RequestNavigation(NavigationRequest e)
        {
            NavAnimationInProgress = true;
            base.RequestNavigation(e);
            NavAnimationInProgress = false;

            var currentStack = NavigationStack;
            var newStackSize = e.NavigationStack.Count;

            bool animated = e.Animated;
            bool removed  = currentStack.Count > newStackSize;

            if (animated)
            {
                var page = (Page)e.NavigationStack[newStackSize - 1];
                if (!removed)
                {
                    UpdateToolbar();
                    if (_drawerToggle != null && NavigationPageController.StackDepth == 2 &&
                        NavigationPage.GetHasBackButton(page))
                    {
                        AnimateArrowIn();
                    }
                }
                else if (_drawerToggle != null && NavigationPageController.StackDepth == 2 &&
                         NavigationPage.GetHasBackButton(page))
                {
                    AnimateArrowOut();
                }
            }
        }
        protected override Task <bool> PushRoot(NavigationPushInfo pushInfo)
        {
            var newPage    = GetInitializedPage(pushInfo);
            var navigation = GetRootNavigation();

            Device.BeginInvokeOnMainThread(async() => {
                try {
                    if (navigation.NavigationStack.Any())
                    {
                        while (navigation.ModalStack.Count > 0)
                        {
                            var page = await navigation.PopModalAsync(true);
                            DisposeModalPage(page);
                        }

                        var hasBackButton = NavigationPage.GetHasBackButton(newPage);
                        NavigationPage.SetHasBackButton(newPage, false);
                        await navigation.PushAsync(newPage);

                        foreach (var page in navigation.NavigationStack.Where(p => p != newPage).ToList())
                        {
                            navigation.RemovePage(page);
                        }

                        NavigationPage.SetHasBackButton(newPage, hasBackButton);
                    }
                    pushInfo.OnCompletedTask?.TrySetResult(true);
                }
                catch (Exception e) {
                    Console.WriteLine(e);
                    pushInfo.OnCompletedTask?.TrySetResult(false);
                }
            });
            return(pushInfo.OnCompletedTask?.Task);
        }
Exemplo n.º 4
0
            public DetailPage()
            {
                var button = new Button {
                    Text = "Click me", AutomationId = NavButton
                };

                button.Clicked += async(o, s) =>
                {
                    var button2 = new Button {
                        Text = "Toggle back button", AutomationId = ToggleBackButton
                    };

                    var page = new ContentPage {
                        Content = new StackLayout {
                            Children =
                            {
                                new Label {
                                    Text = "If there is no hamburger button, this test has failed. If you cannot toggle the back arrow, this test has failed."
                                },
                                button2
                            }
                        }
                    };

                    button2.Clicked += (o2, s2) =>
                    {
                        NavigationPage.SetHasBackButton(page, !NavigationPage.GetHasBackButton(page));
                    };

                    NavigationPage.SetHasBackButton(page, false);
                    await ParentPage.PushAsync(page);
                };
                Content = button;
            }
Exemplo n.º 5
0
        bool ShowBackButton(bool forceShowBackButton)
        {
            if (_navigation == null)
            {
                return(false);
            }

            return(NavigationPage.GetHasBackButton(_navigation.CurrentPage) && (forceShowBackButton || !IsRootPage()));
        }
Exemplo n.º 6
0
            void UpdateHasBackButton()
            {
                if (Child == null)
                {
                    return;
                }

                NavigationItem.HidesBackButton = !NavigationPage.GetHasBackButton(Child);
            }
Exemplo n.º 7
0
        private bool ShowBackButton()
        {
            if (_navigation == null)
            {
                return(false);
            }

            return(NavigationPage.GetHasBackButton(_navigation.CurrentPage) &&
                   !IsRootPage());
        }
Exemplo n.º 8
0
        void UpdateBackButton()
        {
            bool showBackButton = PageController.InternalChildren.Count > 1 && NavigationPage.GetHasBackButton(_currentPage);

            _container.ShowBackButton = showBackButton;

            if (_navManager != null)
            {
                _navManager.AppViewBackButtonVisibility = showBackButton ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed;
            }
        }
        void UpdateBackButton()
        {
            if (_navManager == null)
            {
                return;
            }

            bool showBackButton = Element.InternalChildren.Count > 1 && NavigationPage.GetHasBackButton(_currentPage);

            _navManager.AppViewBackButtonVisibility = showBackButton ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed;
        }
        public void UpdateMenu()
        {
            if (NavigationPage.GetHasBackButton(Element.CurrentPage))
            {
                _toolbar.SetNavigationOnClickListener(_navigationBackListener);
            }
            else
            {
                _toolbar.SetNavigationOnClickListener(null);
            }

            foreach (ToolbarItem item in _toolbarTracker.ToolbarItems)
            {
                item.PropertyChanged -= HandleToolbarItemPropertyChanged;
            }

            IMenu menu = _toolbar.Menu;

            for (var i = 0; i < _toolbarTracker.ToolbarItems.Count(); i++)
            {
                var item = _toolbarTracker.ToolbarItems.ElementAt(i);
                item.PropertyChanged += HandleToolbarItemPropertyChanged;
                var menuItem = menu.GetItem(i);

                if (item.Order == ToolbarItemOrder.Secondary)
                {
                    continue;
                }

                var itemEx = item as ToolbarItemEx;
                if (itemEx == null)
                {
                    continue;
                }

                if (!itemEx.IsVisible)
                {
                    menuItem.SetVisible(false);
                    continue;
                }

                //左側のアイコン設定。NavigationIconを使うためBackButtonとの併用は不可
                //BackButtonよりも優先される。
                //複数の左アイコンが指定されても最後の一つだけが有効となる
                //今の所modalのみで使う方が良い
                if (itemEx.IsLeftIcon)
                {
                    UpdateLeftIcon(itemEx, menuItem);
                    continue;
                }

                UpdateRightIcon(itemEx, menuItem);
            }
        }
Exemplo n.º 11
0
        bool UpButtonShouldNavigate()
        {
            if (CurrentNavigationPage == null)
            {
                return(false);
            }

            bool pagePushed = ((INavigationPageController)CurrentNavigationPage).StackDepth > 1;
            bool pushedPageHasBackButton = NavigationPage.GetHasBackButton(CurrentNavigationPage.CurrentPage);

            return(pagePushed && pushedPageHasBackButton);
        }
        void UpdateBackButton()
        {
            bool showBackButton = Element.InternalChildren.Count > 1 && NavigationPage.GetHasBackButton(_currentPage);

            _container.ShowBackButton = showBackButton;

#if WINDOWS_UWP
            if (_navManager != null)
            {
                _navManager.AppViewBackButtonVisibility = showBackButton ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed;
            }
#endif
        }
Exemplo n.º 13
0
        protected override void OnAppearing()
        {
            base.OnAppearing();
            Application.Current.Properties["LoginUtc"] = DateTime.UtcNow;

            Note.ValueChanged += (s, e) =>
            {
                if (NavigationPage.GetHasBackButton(this))
                {
                    NavigationPage.SetHasBackButton(this, false); // Hide back button because of that users want to back with this button even if not saved
                }
            };
        }
Exemplo n.º 14
0
        void UpdateLeftBarButtonItem(ParentingViewController containerController, Page pageBeingRemoved = null)
        {
            if (containerController == null)
            {
                return;
            }
            var currentChild = containerController.Child;
            var firstPage    = ((NavigationPage)Element).Pages.FirstOrDefault();

            if ((firstPage != pageBeingRemoved && currentChild != firstPage && NavigationPage.GetHasBackButton(currentChild)) || _parentMasterDetailPage == null)
            {
                return;
            }

            SetMasterLeftBarButton(containerController, _parentMasterDetailPage);
        }
Exemplo n.º 15
0
        void UpdateLeftBarButtonItem(ParentingViewController containerController, Page pageBeingRemoved = null)
        {
            if (containerController == null)
            {
                return;
            }
            var currentChild = containerController.Child;
            var firstPage    = ((INavigationPageController)Element).Pages.FirstOrDefault();

            if ((firstPage != pageBeingRemoved && currentChild != firstPage && NavigationPage.GetHasBackButton(currentChild)) || _parentMasterDetailPage == null)
            {
                return;
            }

            if (!_parentMasterDetailPage.ShouldShowToolbarButton())
            {
                containerController.NavigationItem.LeftBarButtonItem = null;
                return;
            }

            var shouldUseIcon = _parentMasterDetailPage.Master.Icon != null;

            if (shouldUseIcon)
            {
                try
                {
                    containerController.NavigationItem.LeftBarButtonItem =
                        new UIBarButtonItem(new UIImage(_parentMasterDetailPage.Master.Icon), UIBarButtonItemStyle.Plain,
                                            (o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented);
                }
                catch (Exception)
                {
                    // Throws Exception otherwise would catch more specific exception type
                    shouldUseIcon = false;
                }
            }

            if (!shouldUseIcon)
            {
                containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(_parentMasterDetailPage.Master.Title,
                                                                                           UIBarButtonItemStyle.Plain,
                                                                                           (o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented);
            }
        }
Exemplo n.º 16
0
 void ToggleBackButton(object sender, EventArgs e)
 {
     NavigationPage.SetHasBackButton(this, !NavigationPage.GetHasBackButton(this));
 }
Exemplo n.º 17
0
 void UpdateBackButton()
 {
     this.Control.HasBackButton = NavigationPage.GetHasBackButton(Element);
 }
        protected virtual void UpdateToolbar()
        {
            ActionBarDrawerToggle toggle = _drawerToggle;

            if (Toolbar == null || NavigationStack.Count == 0 || CurrentPage == null || VirtualView == null)
            {
                return;
            }

            bool isNavigated = NavigationStack.Count > 1;
            Page currentPage = CurrentPage;

            _defaultNavigationIcon ??= Toolbar.NavigationIcon;

            if (isNavigated)
            {
                if (NavigationPage.GetHasBackButton(currentPage))
                {
                    Toolbar.NavigationIcon ??= _defaultNavigationIcon;
                    if (toggle != null)
                    {
                        toggle.DrawerIndicatorEnabled = false;
                        toggle.SyncState();
                    }

                    var prevPage        = (Page)NavigationStack[NavigationStack.Count - 2];
                    var backButtonTitle = NavigationPage.GetBackButtonTitle(prevPage);

                    ImageSource image = NavigationPage.GetTitleIconImageSource(currentPage);
                    if (!string.IsNullOrEmpty(backButtonTitle))
                    {
                        Toolbar.NavigationContentDescription = backButtonTitle;
                    }
                    else if (image == null ||
                             Toolbar.SetNavigationContentDescription(image) == null)
                    {
                        Toolbar.SetNavigationContentDescription(Resource.String.nav_app_bar_navigate_up_description);
                    }
                }
                else if (toggle != null && _flyoutPage != null)
                {
                    toggle.DrawerIndicatorEnabled = _flyoutPage.ShouldShowToolbarButton();
                    toggle.SyncState();
                }
                else
                {
                    Toolbar.NavigationIcon = null;
                }
            }
            else
            {
                if (toggle != null && _flyoutPage != null)
                {
                    toggle.DrawerIndicatorEnabled = _flyoutPage.ShouldShowToolbarButton();
                    toggle.SyncState();
                    Toolbar.SetNavigationContentDescription(Resource.String.nav_app_bar_open_drawer_description);
                }
            }

            Color tintColor = NavigationView.BarBackgroundColor;

            if (tintColor == null)
            {
                Toolbar.BackgroundTintMode = null;
            }
            else
            {
                Toolbar.BackgroundTintMode = PorterDuff.Mode.Src;
                Toolbar.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToNative());
            }

            Brush barBackground = NavigationView.BarBackground;

            Toolbar.UpdateBackground(barBackground);

            Color textColor = NavigationView.BarTextColor;

            if (textColor != null)
            {
                Toolbar.SetTitleTextColor(textColor.ToNative().ToArgb());
            }

            Color navIconColor = NavigationPage.GetIconColor(CurrentPage);

            if (navIconColor != null && Toolbar.NavigationIcon != null)
            {
                DrawableExtensions.SetColorFilter(Toolbar.NavigationIcon, navIconColor, FilterMode.SrcAtop);
            }

            Toolbar.Title = currentPage?.Title ?? string.Empty;

            if (Toolbar.NavigationIcon != null && textColor != null)
            {
                var icon = this.Toolbar.NavigationIcon as DrawerArrowDrawable;
                if (icon != null)
                {
                    icon.Color = textColor.ToNative().ToArgb();
                }
            }

            UpdateTitleIcon();
            UpdateTitleView();
            UpdateToolbarVisibility();
        }
Exemplo n.º 19
0
        void UpdateBackButton()
        {
            bool showBackButton = Element.InternalChildren.Count > 1 && NavigationPage.GetHasBackButton(_currentPage);

            _container.ShowBackButton = showBackButton;
        }
Exemplo n.º 20
0
        public NavigationPropertiesGallery()
        {
            var noBack = new ContentPage
            {
                Title = "No back button",
            };

            NavigationPage.SetHasBackButton(noBack, false);
            var toggleBackButton = new Button {
                Text = "Toggle Back Button"
            };

            toggleBackButton.Clicked += (sender, e) =>
            {
                var hasBack = NavigationPage.GetHasBackButton(noBack);
                if (hasBack)
                {
                    NavigationPage.SetHasBackButton(noBack, false);
                }
                else
                {
                    NavigationPage.SetHasBackButton(noBack, true);
                }
            };
            noBack.Content = toggleBackButton;


            var noBar = new ContentPage
            {
                Title   = "No bar",
                Content = new Label
                {
                    Text  = "No bar content",
                    Style = Device.Styles.TitleStyle
                }
            };

            var backTitle = new ContentPage
            {
                Title = "Back button title"
            };

            NavigationPage.SetHasNavigationBar(noBar, false);

            Content = new ListView
            {
                ItemsSource = new[] {
                    noBack,
                    noBar,
                    backTitle
                },

                ItemTemplate = new DataTemplate(typeof(TextCell))
                {
                    Bindings =
                    {
                        { TextCell.TextProperty, new Binding("Title") }
                    }
                }
            };

            ((ListView)Content).ItemTapped += async(sender, args) =>
            {
                await Navigation.PushAsync((Page)args.Item);
            };

            NavigationPage.SetBackButtonTitle(this, "Back Title");
        }