提前感谢您的帮助。我现在正在开发一个 Forms Shell 应用程序。我的 UI 在很多方面都是数据驱动的,而我想要完成的是一个页面,该页面根据其拥有的模型在 tob 上显示多个选项卡。
换句话说,我尝试完成与 Shells Demo 应用程序相同的布局:
<FlyoutItem Route="animals"
Title="Animals"
FlyoutDisplayOptions="AsSingleItem">
<Tab Title="Domestic"
Route="domestic"
Icon="paw.png">
<ShellContent Route="cats"
Style="{StaticResource DomesticShell}"
Title="Cats"
Icon="cat.png"
ContentTemplate="{DataTemplate views:CatsPage}" />
<ShellContent Route="dogs"
Style="{StaticResource DomesticShell}"
Title="Dogs"
Icon="dog.png"
ContentTemplate="{DataTemplate views:DogsPage}" />
</Tab>
</FlyoutItem>
但从 FlyoutMenu 中的现有链接开始。就像上面的“国内”选项卡的级别一样,当导航到创建两个或多个 Shell 顶部点击页面时。
我知道我可以使用TappedPage 作为ShellContent,但是TappedPages 的样式有点不同我想知道我是否可以使用“本机”Shell 功能来实现这一点。
我已经尝试过类似的东西:
ShellSection tab1 = new ShellSection
{
Title = "Tab1"
};
tab1.Items.Add(new ShellContent() { Title = "Test1", Content = new ContentPage() { Title = "Test1" } });
tab1.Items.Add(new ShellContent() { Title = "Test2", Content = new ContentPage() { Title = "Test2" } });
var current = AppShell.Current.CurrentItem;
current.Items.Add(tab1);
但这也在底部标签栏和弹出菜单中添加了另一个条目,这是我不想要的。
为了更清楚,我尝试用样机截图来解释它。
假设我们有以下弹出菜单,其中国内条目。
这个国内条目通向一个页面,该页面的视图模型提供了应在选项卡中显示的数据集合。
如您所见,此页面在标题视图中提供了一个链接,该链接打开一个弹出窗口以更改所选元素,并应刷新/更改显示的数据,例如具有三个选项卡。
我希望它现在更清楚。
编辑:
到目前为止的评论让我更进一步。通过以下代码,我完成了获得所需的顶部选项卡。
var current = AppShell.Current.CurrentItem;
var currentSection = current.CurrentItem;
//currentSection.Items.Clear();
currentSection.Items.Add(new CatsPage() { Title = "Tab1"} ); ;
currentSection.Items.Add(new ShellContent() { Title = "Tab2", Content = new CatsPage() });
但它仍然不完美 - 在添加的页面中,按钮标签栏是隐藏的,有什么解决方案吗?