private void BindingContextPageChanged(object sender, BindingContextChangeRequestMessage messageArgs)
        {
            if (MainPage != null)
            {
                // Same as with the page; the app state is about to change
                NavAndMenuBar.OnAppStateChanged(MainPage, messageArgs.PreventNavStackPush);

                MainPage.BindingContext = messageArgs.Payload;
            }
        }
        private void MainPageChanged(object sender, MainPageChangeRequestMessage messageArgs)
        {
            // Try to avoid changing the page is possible
            if (
                messageArgs?.Payload == null
                ||
                MainPage == null
                ||
                (
                    _lastMainPage != null
                    &&
                    _lastMainPage.GetType() == messageArgs.Payload.GetType()
                )
                )
            {
                return;
            }

            // Notify the nav bar directly before the change so it can preserve the existing main page binding context app state
            NavAndMenuBar.OnAppStateChanged(MainPage, messageArgs.PreventNavStackPush);

            MainPage = messageArgs.Payload;

            // IMPORTANT -- The assignment above often fails to cause Page.Disappearing for some reason
            if (_lastMainPage != null)
            {
                if (_lastMainPage is IDisposable lastMainPageAsDisposablew)
                {
                    lastMainPageAsDisposablew.Dispose();
                }

                _lastMainPage = null;
            }

            _lastMainPage = MainPage;
        }