Ejemplo n.º 1
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
            };
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        void ApplyChanges()
        {
            var currentPage = _shell.CurrentPage;

            if (_currentPage != _shell.CurrentPage)
            {
                if (_currentPage != null)
                {
                    _currentPage.PropertyChanged -= OnCurrentPagePropertyChanged;
                }

                _currentPage = currentPage;

                if (_currentPage != null)
                {
                    _currentPage.PropertyChanged += OnCurrentPagePropertyChanged;
                }
            }

            if (currentPage == null)
            {
                return;
            }

            var stack = _shell.Navigation.NavigationStack;

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

            _toolbarTracker.Target = _shell;

            Page previousPage = null;

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

            ToolbarItems = _toolbarTracker.ToolbarItems;
            UpdateBackbuttonBehavior();
            bool backButtonVisible = true;

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

            BackButtonVisible = backButtonVisible && stack.Count > 1;
            BackButtonEnabled = _backButtonBehavior?.IsEnabled ?? true;

            if (_backButtonBehavior?.Command != null)
            {
                BackButtonEnabled =
                    BackButtonEnabled &&
                    _backButtonBehavior.Command.CanExecute(_backButtonBehavior.CommandParameter);
            }

            UpdateTitle();

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

            if (_currentPage != null &&
                _currentPage.IsSet(Shell.NavBarIsVisibleProperty))
            {
                IsVisible = Shell.GetNavBarIsVisible(_currentPage);
            }
            else
            {
                IsVisible = (BackButtonVisible ||
                             !String.IsNullOrEmpty(Title) ||
                             TitleView != null ||
                             _toolbarTracker.ToolbarItems.Count > 0);
            }

            if (currentPage != null)
            {
                DynamicOverflowEnabled = PlatformConfiguration.WindowsSpecific.Page.GetToolbarDynamicOverflowEnabled(currentPage);
            }
        }