Task CreateNavigationViewHandlerAsync(INavigationView navigationView, Func <NavigationViewHandler, Task> action)
        {
            return(InvokeOnMainThreadAsync(async() =>
            {
                FrameworkElement frameworkElement = null;
                var content = (Panel)DefaultWindow.Content;
                try
                {
                    var mauiContext = MauiContext.MakeScoped(true);
                    var handler = CreateHandler(navigationView, mauiContext);
                    frameworkElement = handler.NativeView;
                    content.Children.Add(frameworkElement);
                    if (navigationView is NavigationViewStub nvs && nvs.NavigationStack?.Count > 0)
                    {
                        navigationView.RequestNavigation(new NavigationRequest(nvs.NavigationStack, false));
                        await nvs.OnNavigationFinished;
                    }

                    await action(handler);
                }
                finally
                {
                    if (frameworkElement != null)
                    {
                        content.Children.Remove(frameworkElement);
                    }
                }
            }));
        }
        Task CreateNavigationViewHandlerAsync(INavigationView navigationView, Func <NavigationViewHandler, Task> action)
        {
            return(InvokeOnMainThreadAsync(async() =>
            {
                ViewGroup rootView = (DefaultContext as AppCompatActivity).Window.DecorView as ViewGroup;
                var linearLayoutCompat = new LinearLayoutCompat(DefaultContext);
                var fragmentManager = MauiContext.GetFragmentManager();
                var viewFragment = new NavViewFragment(MauiContext);

                try
                {
                    linearLayoutCompat.Id = View.GenerateViewId();

                    fragmentManager
                    .BeginTransaction()
                    .Add(linearLayoutCompat.Id, viewFragment)
                    .Commit();

                    rootView.AddView(linearLayoutCompat);
                    await viewFragment.FinishedLoading;
                    var handler = CreateHandler(navigationView, viewFragment.ScopedMauiContext);

                    if (navigationView is NavigationViewStub nvs && nvs.NavigationStack?.Count > 0)
                    {
                        navigationView.RequestNavigation(new NavigationRequest(nvs.NavigationStack, false));
                        await nvs.OnNavigationFinished;
                    }

                    await action(handler);
                }
                finally
                {
                    rootView.RemoveView(linearLayoutCompat);

                    fragmentManager
                    .BeginTransaction()
                    .Remove(viewFragment)
                    .Commit();
                }
            }));
        }