在我的应用程序中,我使用 Xamarin Shell 创建了一个底部标签栏导航,如下所示:
主页.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.'
,我不知道这意味着什么,并且想知道是否有任何修复或解决方法?
聊天机器人页面.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());
}
}