我有一个标签视图设计在我的xamarin应用程序,我需要通过导航控制它,并出现特定的页面,我把它默认在第一页,并希望浏览第二个。
this is my TabView:
<Grid>
<xct:TabView
TabStripPlacement="Bottom"
TabStripBackgroundColor="White"
TabStripHeight="60"
TabIndicatorColor="#2196f3"
TabContentBackgroundColor="#2196f3">
<xct:TabViewItem
Icon="triangle.png"
Text="Patient Details"
TextColor="#2196f3"
TextColorSelected="#2196f3"
FontSize="12"
>
<Grid
BackgroundColor="Gray">
<Label
HorizontalOptions="Center"
VerticalOptions="Center"
Text="TabContent1" />
</Grid>
</xct:TabViewItem>
<xct:TabViewItem
Icon="circle.png"
Text="Patient Follows up"
TextColor="#2196f3"
TextColorSelected="#2196f3"
FontSize="12">
<Grid>
<Label
HorizontalOptions="Center"
VerticalOptions="Center"
Text="TabContent2" />
</Grid>
</xct:TabViewItem>
</xct:TabView>
</Grid>
我们无法在TabView
中导航页面。TabView
项只接受视图。这个问题以前已经问过了,现在没有支持的功能。
你可以用Shell
代替。Shell
支持分页。你还可以用路由来导航到特定的标签页。
对于Shell
中的选项卡,您可以直接使用Tabbar
或使用FlyoutItem
中的选项卡来实现Shell中TabView的类似功能。
注册路由:
<Shell ...>
<FlyoutItem ...
Route="animals">
<Tab ...
Route="domestic">
<ShellContent ...
Route="cats" />
<ShellContent ...
Route="dogs" />
</Tab>
...
</Shell>
导航到cats页面:
await Shell.Current.GoToAsync("//animals/domestic/cats");
要了解更多细节,您可以参考MS文档。https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation