Exemplo n.º 1
0
        // This is used to fire NavigationFinished back to the xplat view
        // Firing NavigationFinished from Loaded is the latest reliable point
        // in time that I know of for firing `NavigationFinished`
        // Ideally we could fire it when the `NavigationTransitionInfo` is done but
        // I haven't found a way to do that
        void OnNavigated(object sender, UI.Xaml.Navigation.NavigationEventArgs e)
        {
            // If the user has inserted or removed any extra pages
            SyncBackStackToNavigationStack(NavigationStack);

            if (e.Content is not FrameworkElement fe)
            {
                return;
            }

            if (e.Content is not Page page)
            {
                return;
            }


            ContentPresenter?presenter;

            if (page.Content == null)
            {
                presenter = new ContentPresenter()
                {
                    HorizontalAlignment = UI.Xaml.HorizontalAlignment.Stretch,
                    VerticalAlignment   = UI.Xaml.VerticalAlignment.Stretch
                };

                page.Content = presenter;
            }
            else
            {
                presenter = page.Content as ContentPresenter;
            }

            // At this point if the Content isn't a ContentPresenter the user has replaced
            // the conent so we just let them take control
            if (presenter == null || _currentPage == null)
            {
                return;
            }

            try
            {
                presenter.Content = _currentPage.ToPlatform(MauiContext);
            }
            catch (Exception)
            {
                FireNavigationFinished();
                throw;
            }

            fe.OnLoaded(() =>
            {
                FireNavigationFinished();
                if (NavigationView is IView view)
                {
                    view.Arrange(fe);
                }
            });
        }
Exemplo n.º 2
0
        // This is used to fire NavigationFinished back to the xplat view
        // Firing NavigationFinished from Loaded is the latest reliable point
        // in time that I know of for firing `NavigationFinished`
        // Ideally we could fire it when the `NavigationTransitionInfo` is done but
        // I haven't found a way to do that
        void OnNavigated(object sender, UI.Xaml.Navigation.NavigationEventArgs e)
        {
            // If the user has inserted or removed any extra pages
            SyncBackStackToNavigationStack(NavigationStack);

            if (e.Content is not FrameworkElement fe)
            {
                return;
            }

            if (e.Content is not Page page)
            {
                return;
            }


            ContentPresenter?presenter;

            if (page.Content == null)
            {
                presenter = new ContentPresenter()
                {
                    HorizontalAlignment = UI.Xaml.HorizontalAlignment.Stretch,
                    VerticalAlignment   = UI.Xaml.VerticalAlignment.Stretch
                };

                page.Content = presenter;
            }
            else
            {
                presenter = page.Content as ContentPresenter;
            }

            // At this point if the Content isn't a ContentPresenter the user has replaced
            // the conent so we just let them take control
            if (presenter == null || _currentPage == null)
            {
                return;
            }

            presenter.Content = _currentPage.ToNative(MauiContext);

            if (fe.IsLoaded)
            {
                NavigationView?.NavigationFinished(NavigationStack);
                return;
            }

            fe.Loaded += OnLoaded;
            void OnLoaded(object sender, RoutedEventArgs e)
            {
                fe.Loaded -= OnLoaded;
                NavigationView?.NavigationFinished(NavigationStack);
            }
        }