【发布时间】:2021-05-29 02:39:23
【问题描述】:
我的 AppShell 中有一个 TabBar,它有五个选项卡。
这些选项卡中的三个是 ContentPages,而另外两个是 TabbedPages。带有 ContentPages 的所有三个选项卡都可以正常打开,但是带有 TabbedPages 的两个选项卡给了我“指定的转换无效”错误。
AppShell.xaml
<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ReleaseVerificationAndroid.Views"
Title="ReleaseVerificationAndroid"
x:Class="ReleaseVerificationAndroid.AppShell">
<TabBar x:Name="MainTab" Route="HomePage">
<Tab Title="Home" Icon="icon_home.png">
<ShellContent Route="HomePage" ContentTemplate="{DataTemplate local:HomePage}"/>
</Tab>
<Tab Title="Fingerprints" Icon="icon_fingerprint.png" IsVisible="True">
<ShellContent Route="FingerprintPage" ContentTemplate="{DataTemplate local:FingerprintPage}"/>
</Tab>
<Tab Title="Mugshots" Icon="icon_mugshot.png" IsVisible="True">
<ShellContent Route="MugshotPage" ContentTemplate="{DataTemplate local:MugshotPage}"/>
</Tab>
<Tab Title="Irises" Icon="icon_iris.png" IsVisible="True">
<ShellContent Route="IrisPage" ContentTemplate="{DataTemplate local:IrisPage}"/>
</Tab>
<Tab Title="Result" Icon="icon_feed.png">
<ShellContent Route="ResultPage" ContentTemplate="{DataTemplate local:ResultPage}"/>
</Tab>
</TabBar>
</Shell>
IrisPage.xaml(标签页)
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ReleaseVerificationAndroid.Views.IrisPage"
Title="{Binding Title}"
xmlns:local="clr-namespace:ReleaseVerificationAndroid.Views"
xmlns:vm="clr-namespace:ReleaseVerificationAndroid.ViewModels">
<NavigationPage Title="Left Iris" IconImageSource="icon_iris">
<x:Arguments>
<local:LeftIrisPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Right Iris" IconImageSource="icon_iris">
<x:Arguments>
<local:RightIrisPage />
</x:Arguments>
</NavigationPage>
</TabbedPage>
LeftIrisPage 的内容
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:vm="clr-namespace:ReleaseVerificationAndroid.ViewModels"
x:Class="ReleaseVerificationAndroid.Views.LeftIrisPage">
<ContentPage.BindingContext>
<vm:LeftIrisViewModel />
</ContentPage.BindingContext>
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="75"/>
<RowDefinition Height="*" />
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<ContentView Grid.Row="0" Padding="0,10,0,0" VerticalOptions="FillAndExpand">
<Image Source="mentalix_logo.png" VerticalOptions="Center" HeightRequest="48" />
</ContentView>
<Frame Grid.Row="1" Margin="10,0,10,10" BackgroundColor="Transparent"
BorderColor="#333333"
CornerRadius="0"
HasShadow="True">
<ContentView VerticalOptions="CenterAndExpand">
<Image VerticalOptions="Center" HeightRequest="500" />
</ContentView>
</Frame>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Margin="10,0,10,12.5" Text="Scan"
Command="{Binding RescanLeftIrisCmd}"
BackgroundColor="{StaticResource PrimaryButton}"
TextColor="White" />
<Button Grid.Column="1" Margin="2.5,0,10,12.5" Text="Clear"
Command="{Binding ClearLeftIrisCmd}"
BackgroundColor="{StaticResource Primary}"
TextColor="White" />
</Grid>
</Grid>
</ContentPage.Content>
</ContentPage>
【问题讨论】:
-
为什么要使用 TabbedPage 和 Shell Tabbar/Tab ?
-
我正在尝试创建嵌套选项卡式层次结构。五个主要选项卡是主页、指纹、面部照片、虹膜和结果。我想为指纹和虹膜添加两个嵌套选项卡(左右各)
-
你不能嵌套 TabbedPages
-
只要确保我们在同一个页面上,我不会将 TabbedPages 嵌套在 TabbedPage 中,而是在 TabBar ContentPage 中添加 TabbedPage。如果这不可能,有什么替代方案?
标签: c# xaml xamarin.forms tabbedpage xamarin.forms.shell