예제 #1
0
        void UpdateBackbuttonBehavior()
        {
            var bbb = Shell.GetBackButtonBehavior(_currentPage);

            if (bbb == _backButtonBehavior)
            {
                return;
            }

            if (_backButtonBehavior != null)
            {
                _backButtonBehavior.PropertyChanged -= OnBackButtonPropertyChanged;
            }

            _backButtonBehavior = bbb;

            if (_backButtonBehavior != null)
            {
                _backButtonBehavior.PropertyChanged += OnBackButtonPropertyChanged;
            }

            void OnBackButtonPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                ApplyChanges();

                if (_backButtonBehavior.Command == _backButtonCommand)
                {
                    return;
                }

                if (_backButtonCommand != null)
                {
                    _backButtonCommand.CanExecuteChanged -= OnBackButtonCanExecuteChanged;
                }

                _backButtonCommand = _backButtonBehavior.Command;

                if (_backButtonCommand != null)
                {
                    _backButtonCommand.CanExecuteChanged += OnBackButtonCanExecuteChanged;
                }
            }

            void OnBackButtonCanExecuteChanged(object sender, EventArgs e)
            {
                BackButtonEnabled =
                    _backButtonCommand.CanExecute(_backButtonBehavior.CommandParameter);
            }
        }
예제 #2
0
        void ApplyChanges()
        {
            if (_shell.CurrentPage == null)
            {
                return;
            }

            var stack = _shell.Navigation.NavigationStack;

            if (stack.Count == 0)
            {
                return;
            }

            var currentPage = _shell.CurrentPage;

            _toolbarTracker.Target = currentPage;

            Page previousPage = null;

            if (stack.Count > 1)
            {
                previousPage = stack[stack.Count - 1];
            }

            ToolbarItems        = _toolbarTracker.ToolbarItems;
            IsVisible           = _shell.GetEffectiveValue <bool>(Shell.NavBarIsVisibleProperty, true);
            _backButtonBehavior = _shell.GetEffectiveValue <BackButtonBehavior>(Shell.BackButtonBehaviorProperty, null);
            bool backButtonVisible = true;

            if (_backButtonBehavior != null)
            {
                backButtonVisible = _backButtonBehavior.IsVisible;
            }

            BackButtonVisible = backButtonVisible && stack.Count > 1;
            Title             = (!String.IsNullOrWhiteSpace(currentPage.Title)) ? currentPage.Title : _shell.Title;

            TitleView = _shell.GetEffectiveValue <VisualElement>(Shell.TitleViewProperty, null);

            if (currentPage != null)
            {
                DynamicOverflowEnabled = PlatformConfiguration.WindowsSpecific.Page.GetToolbarDynamicOverflowEnabled(currentPage);
            }
        }
예제 #3
0
        public ShellToolbar(Shell shell) : base(shell)
        {
            _shell                 = shell;
            shell.Navigated       += (_, __) => ApplyChanges();
            shell.PropertyChanged += (_, p) =>
            {
                if (p.Is(Shell.BackButtonBehaviorProperty))
                {
                    if (_backButtonBehavior != null)
                    {
                        _backButtonBehavior.PropertyChanged -= OnBackButtonPropertyChanged;
                    }

                    _backButtonBehavior =
                        _shell.GetEffectiveValue <BackButtonBehavior>(Shell.BackButtonBehaviorProperty, null);

                    if (_backButtonBehavior != null)
                    {
                        _backButtonBehavior.PropertyChanged += OnBackButtonPropertyChanged;
                    }
                }
                else if (p.IsOneOf(
                             Shell.CurrentItemProperty,
                             Shell.FlyoutBehaviorProperty,
                             Shell.BackButtonBehaviorProperty))
                {
                    ApplyChanges();
                }
            };

            shell.HandlerChanged += (_, __) => ApplyChanges();
            _backButtonBehavior   =
                _shell.GetEffectiveValue <BackButtonBehavior>(Shell.BackButtonBehaviorProperty, null);

            if (_backButtonBehavior != null)
            {
                _backButtonBehavior.PropertyChanged += OnBackButtonPropertyChanged;
            }

            ApplyChanges();
            _toolbarTracker.CollectionChanged += (_, __) => ToolbarItems = _toolbarTracker.ToolbarItems;
            _toolbarTracker.AdditionalTargets  = new List <Page> {
                shell
            };
        }