.net MAUI,android System.InvalidOperationException:导航上“未设置本机视图”

ant*_*hio 5 c# android maui

找不到邪恶的根源,有两个页面,添加为单例服务,当我第一次导航到第二页时一切都很好,当我第二次导航时我得到:

System.InvalidOperationException: 'Native View not set'
Run Code Online (Sandbox Code Playgroud)
MAUI version 6.0.300-rc.2.5513+sha.8a017cf73-azdo.6048189
Run Code Online (Sandbox Code Playgroud)

模拟器 Android11 API 30

在桌面上测试一切似乎都正常......

MauiProgram.cs

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });

        
        builder.Services.AddSingleton<ShellViewModel>();

        builder.Services.AddSingleton<AppShell>();
        builder.Services.AddSingleton<MainPage>();
        builder.Services.AddSingleton<SettingsPage>();



        return builder.Build();
    }
}
Run Code Online (Sandbox Code Playgroud)

App.xaml - 默认为新项目App.cs

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new AppShell();

        Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));
        Routing.RegisterRoute(nameof(SettingsPage), typeof(SettingsPage));
    }
}
Run Code Online (Sandbox Code Playgroud)

AppShell.xaml

<?xml version="1.0" encoding="UTF-8" ?>
<Shell
    x:Class="MauiAppTest.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:MauiAppTest"
    xmlns:vm="clr-namespace:MauiAppTest.ViewModels"
    x:DataType="vm:ShellViewModel"
    
    Shell.FlyoutBehavior="Disabled">
    <Shell.ToolbarItems>
        <ToolbarItem Command="{Binding GoToSettings}" Text="Settings"/>
    </Shell.ToolbarItems>
    <ShellContent
        Title="Hello, World!"
        ContentTemplate="{DataTemplate local:MainPage}"
        Route="MainPage" />

</Shell>
Run Code Online (Sandbox Code Playgroud)

AppShell.cs

public partial class AppShell : Shell
{
    public AppShell()
    {
        InitializeComponent();

        BindingContext = new ShellViewModel();
    }
}
Run Code Online (Sandbox Code Playgroud)

ShellViewModel.cs

    public class ShellViewModel: ObservableObject
    {
        public AsyncRelayCommand GoToSettings { get; private set; }

        public ShellViewModel()
        {
            GoToSettings = new AsyncRelayCommand(async () => await Shell.Current.GoToAsync("SettingsPage"));
        }
    }
Run Code Online (Sandbox Code Playgroud)

MainPage和SettingsPage只是两个默认的空白页

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiAppTest.MainPage"
             Title="MainPage">
    <StackLayout>
        <Label Text="Welcome to .NET MAUI!"
                VerticalOptions="Center" 
                HorizontalOptions="Center" />
    </StackLayout>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiAppTest.SettingsPage"
             Title="SettingsPage">
    <StackLayout>
        <Label Text="Welcome to .NET MAUI!"
                VerticalOptions="Center" 
                HorizontalOptions="Center" />
    </StackLayout>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)