PushAsync 导航上的 Xamarin Forms 'DrawerLayout must be measured with MeasureSpec.EXACTLY.' 错误

Xamarin Forms 'DrawerLayout must be measured with MeasureSpec.EXACTLY.' error on PushAsync Navigation

在我的应用中,我使用 Xamarin Shell 创建了一个底部标签栏导航,如下所示:

MainPage.xaml

<!--TabBar Styles and Resources-->
    <Shell.Resources>
        <ResourceDictionary>
            <Style x:Key="FreeStyle" TargetType="Element">
                <Setter Property="Shell.TabBarBackgroundColor" Value="#f7f7f7" />
                <Setter Property="Shell.TabBarForegroundColor" Value="White"/>
                <Setter Property="Shell.TabBarUnselectedColor" Value="#999999"/>
                <Setter Property="Shell.TabBarTitleColor" Value="#61c9f7"/>
            </Style>
        </ResourceDictionary>
    </Shell.Resources>


    <!--BluePill Pages-->
    <TabBar Style="{StaticResource FreeStyle}">
        <!--TeleMED Tab-->
        <Tab Icon="telemedicineIcon.png">
            <ShellContent ContentTemplate="{DataTemplate views:TelemedicineMainPage}"/>
        </Tab>

        <!--FlemingTab-->
        <Tab Icon="chatbotIcon.png">
            <ShellContent ContentTemplate="{DataTemplate views:ChatbotPage}"/>
        </Tab>

        <!--FirstAid Tab-->
        <Tab Icon="firstaidIcon.png">
            <ShellContent ContentTemplate="{DataTemplate views:FirstAidPage}"/>
        </Tab>

        <!--User Profile Tab-->
        <Tab Icon="profileIcon.png">
            <ShellContent ContentTemplate="{DataTemplate views:UserProfilePage}"/>
        </Tab>
    </TabBar>

ChatbotPage.xaml 中,我想完全删除标签栏,所以我在它的代码后面实现了 Shell.SetTabBarIsVisible(this, false); 并在其中一个标签上添加了一个 TapGesture 以便它带我回到主页。
每当我 运行 应用程序并点击 ChatbotPage 中的后退按钮时,我都会收到此异常
Java.Lang.IllegalArgumentException: 'DrawerLayout must be measured with MeasureSpec.EXACTLY.'
我不知道这意味着什么,想知道是否有任何修复或解决方法?

ChatbotPage.xaml

<!--Chatbot Header and Back Button-->
        <Frame BackgroundColor="#f7f7f7" Grid.Row="0" HasShadow="True">
            <StackLayout Orientation="Horizontal">
                <renderers:FontAwesomeIcon Text="{x:Static helpers:IconsFA.BackArrow}" HorizontalOptions="Start">
                    <Label.GestureRecognizers>
                        <TapGestureRecognizer Tapped="BacktoMain_Button"/>
                    </Label.GestureRecognizers>
                </renderers:FontAwesomeIcon>

                <StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
                    <Frame BackgroundColor="Gray" 
                           Padding="0" 
                           CornerRadius="100"
                           HasShadow="False"
                           IsClippedToBounds="True"
                           HeightRequest="35"
                           WidthRequest="35">

                        <Image HorizontalOptions="Center"
                               VerticalOptions="Center"/>
                    </Frame>

                    <Label Text="Fleming"
                           TextColor="Black"
                           FontAttributes="Bold"
                           FontSize="18"
                           VerticalOptions="Center"/>
                </StackLayout>
            </StackLayout>
        </Frame>

ChatbotPage.xaml.cs

[XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class ChatbotPage : ContentPage
    {
        public ChatbotPage()
        {
            InitializeComponent();

            Shell.SetTabBarIsVisible(this, false);
        }

        private async void BacktoMain_Button(object sender, EventArgs e)
        {
            await Navigation.PushAsync(new MainPage());
        }
    }

使用 await Navigation.PushAsync(new MainPage()); 不会将您带回到您正在使用的 MainPage,这行代码将推送到一个新的 MainPage

要select以编程方式在标签栏下的不同标签,您可以使用:

private void Button_Clicked(object sender, EventArgs e)
{
    TabBar bar = Shell.Current.Items[0] as TabBar;

    //Select the first Tab
    bar.CurrentItem = bar.Items[0];

    //If you want to select the second tab, you can use bar.CurrentItem = bar.Items[1]; the same as the third tab, the fourth tab......
}

我上传了一个样本 here