void UpdateTitleView()
        {
            AToolbar bar = _toolbar;

            if (bar == null)
            {
                return;
            }

            Page currentPage = Element.CurrentPage;

            if (currentPage == null)
            {
                return;
            }

            VisualElement titleView = NavigationPage.GetTitleView(currentPage);

            if (_titleViewRenderer != null)
            {
                var reflectableType = _titleViewRenderer as System.Reflection.IReflectableType;
                var rendererType    = reflectableType != null?reflectableType.GetTypeInfo().AsType() : _titleViewRenderer.GetType();

                if (titleView == null || Registrar.Registered.GetHandlerTypeForObject(titleView) != rendererType)
                {
                    if (_titleView != null)
                    {
                        _titleView.Child = null;
                    }
                    Platform.ClearRenderer(_titleViewRenderer.View);
                    _titleViewRenderer.Dispose();
                    _titleViewRenderer = null;
                }
            }

            if (titleView == null)
            {
                return;
            }

            if (_titleViewRenderer != null)
            {
                _titleViewRenderer.SetElement(titleView);
            }
            else
            {
                _titleViewRenderer = Platform.CreateRenderer(titleView, Context);

                if (_titleView == null)
                {
                    _titleView = new Container(Context);
                    bar.AddView(_titleView);
                }

                _titleView.Child = _titleViewRenderer;
            }

            Platform.SetRenderer(titleView, _titleViewRenderer);
        }
        void ResetToolbar()
        {
            AToolbar oldToolbar = _toolbar;

            _toolbar.SetNavigationOnClickListener(null);
            _toolbar.RemoveFromParent();

            _toolbar.RemoveView(_titleView);
            _titleView = null;

            if (_titleViewRenderer != null)
            {
                Platform.ClearRenderer(_titleViewRenderer.View);
                _titleViewRenderer.Dispose();
                _titleViewRenderer = null;
            }

            _toolbar.RemoveView(_titleIconView);
            _titleIconView = null;

            _imageSource = null;

            _toolbar = null;

            SetupToolbar();

            // if the old toolbar had padding from transluscentflags, set it to the new toolbar
            if (oldToolbar.PaddingTop != 0)
            {
                _toolbar.SetPadding(0, oldToolbar.PaddingTop, 0, 0);
            }

            RegisterToolbar();
            UpdateToolbar();
            UpdateMenu();

            // Preserve old values that can't be replicated by calling methods above
            if (_toolbar != null)
            {
                _toolbar.Subtitle = oldToolbar.Subtitle;
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                Device.Info.PropertyChanged -= DeviceInfoPropertyChanged;

                if (NavigationPageController != null)
                {
                    var navController = NavigationPageController;

                    navController.PushRequested             -= OnPushed;
                    navController.PopRequested              -= OnPopped;
                    navController.PopToRootRequested        -= OnPoppedToRoot;
                    navController.InsertPageBeforeRequested -= OnInsertPageBeforeRequested;
                    navController.RemovePageRequested       -= OnRemovePageRequested;
                }

                if (Current != null)
                {
                    Current.PropertyChanged -= CurrentOnPropertyChanged;
                }

                FragmentManager fm = FragmentManager;

                if (!fm.IsDestroyed)
                {
                    FragmentTransaction trans = fm.BeginTransactionEx();
                    foreach (Fragment fragment in _fragmentStack)
                    {
                        trans.RemoveEx(fragment);
                    }
                    trans.CommitAllowingStateLossEx();
                    fm.ExecutePendingTransactionsEx();
                }

                _toolbar.RemoveView(_titleView);
                _titleView?.Dispose();
                _titleView = null;

                if (_titleViewRenderer != null)
                {
                    Platform.ClearRenderer(_titleViewRenderer.View);
                    _titleViewRenderer.Dispose();
                    _titleViewRenderer = null;
                }

                _toolbar.RemoveView(_titleIconView);
                _titleIconView?.Dispose();
                _titleIconView = null;

                _imageSource = null;

                if (_toolbarTracker != null)
                {
                    _toolbarTracker.CollectionChanged -= ToolbarTrackerOnCollectionChanged;

                    _toolbar.DisposeMenuItems(_currentToolbarItems, OnToolbarItemPropertyChanged);

                    _toolbarTracker.Target = null;
                    _toolbarTracker        = null;
                }

                if (_currentMenuItems != null)
                {
                    _currentMenuItems.Clear();
                    _currentMenuItems = null;
                }

                if (_currentToolbarItems != null)
                {
                    _currentToolbarItems.Clear();
                    _currentToolbarItems = null;
                }

                if (_toolbar != null)
                {
                    _toolbar.SetNavigationOnClickListener(null);
                    _toolbar.Menu.Clear();

                    RemoveView(_toolbar);

                    _toolbar.Dispose();
                    _toolbar = null;
                }

                if (_drawerLayout.IsAlive() && _drawerListener.IsAlive())
                {
                    _drawerLayout.RemoveDrawerListener(_drawerListener);

                    RemoveView(_drawerLayout);
                }

                if (_drawerListener != null)
                {
                    _drawerListener.Dispose();
                    _drawerListener = null;
                }

                if (_drawerToggle != null)
                {
                    _drawerToggle.ToolbarNavigationClickListener = null;
                    _drawerToggle.Dispose();
                    _drawerToggle = null;
                }

                if (_backgroundDrawable != null)
                {
                    _backgroundDrawable.Dispose();
                    _backgroundDrawable = null;
                }

                Current = null;

                // We dispose the child renderers after cleaning up everything related to DrawerLayout in case
                // one of the children is a FlyoutPage (which may dispose of the DrawerLayout).
                if (Element != null)
                {
                    foreach (Element element in PageController.InternalChildren)
                    {
                        var child = element as VisualElement;
                        if (child == null)
                        {
                            continue;
                        }

                        IVisualElementRenderer renderer = Platform.GetRenderer(child);
                        renderer?.Dispose();
                    }
                }
            }

            base.Dispose(disposing);
        }