c# - Xamarin.Forms Shell 选项卡仅显示列表中的最后一个选项卡
问题描述
我正在将现有代码迁移到 Xamarin Forms 4.0 Shell
,以前我正在使用TabbedPage
,但现在我想使用Shell
Tabs。
以下是迁移后代码的样子。我注意到的是它只显示一个顶部选项卡,该选项卡在列表中具有最后一个条目。就我而言,它只显示 Tab2。
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:App.Views.Tabs;assembly=App"
x:Class="App.Views.AppShell"
x:Name="self">
<TabBar>
<Tab>
<ShellContent>
<views:Tab1Page BindingContext="{x:Reference self}" Title="Tab1" />
<views:Tab2Page BindingContext="{x:Reference self}" Title="Tab2"/>
</ShellContent>
</Tab>
</TabBar>
</Shell>
解决方案
尝试使用以下代码:
<Shell>
...
<Tab>
<ShellContent Title="Tab1"> <!-- title in the tab -->
<views:Tab1Page} Title="Tab1" BindingContext="{x:Reference self}"/>
<!-- Title in the navigation bar -->
</ShellContent>
<ShellContent Title="Tab2">
<views:Tab2Page} Title="Tab2" BindingContext="{x:Reference self}"/>
</ShellContent>
</Tab>
...
</Shell>
微软文档
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/tabs
推荐阅读
- java - 如何在 Maven src.xml 中包含来自上述目录的文件?
- html - 我们可以用于消息功能的按钮类型是什么?
- powershell - 使用 -lt 但不使用 -gt 或 -eq 输出报告
- javascript - 如何在我的代码中添加“keyup”以使用键盘按钮左右移动画廊幻灯片?
- python - 使用 PyGithub 在两个公司 GitHub 帐户之间创建一个存储库
- matpower - 如何在 MATPOWER 中保存多次运行的最佳潮流结果?
- apache-spark - Hadoop客户端无法连接到datanode
- javascript - 带有函数的ajax响应返回
- c# - Add tabs to tab control from same DataTemplate but they shouldn't be connected to each other
- c# - 从 ML.Net 中的模型获取 MaximumEntropyModelParameters