shell 中的固定标签栏

fixed tabbar in shell

是否可以确保(仪表板/统计信息)选项卡保持固定而不会被各种 FlyoutItem 选项修改?谢谢

image

 <TabBar>
    <Tab Title="Dasboard">
        <Tab.Icon>
            <FontImageSource FontFamily="{StaticResource FontAwesomeSolid}"
                            Glyph="{StaticResource IconHome}"
                            Color="Black"/>
        </Tab.Icon>
        <ShellContent Route="HomePage"  ContentTemplate="{DataTemplate _v:AccountPage}" />
    </Tab>
    <Tab Title="Statistiche">
        <ShellContent Route="ItemsPage" ContentTemplate="{DataTemplate _v:AccountPage}" />
    </Tab>
</TabBar>

<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
    <ShellContent Title="Online Store" Icon="ic_online_store" ContentTemplate="{DataTemplate _v:AccountPage}" />
    <ShellContent Title="About Us" Icon="ic_about_us" ContentTemplate="{DataTemplate _v:AccountPage}" />
    <ShellContent Title="Contact Us" Icon="ic_contact_us" ContentTemplate="{DataTemplate _v:AccountPage}" />
    <ShellContent Title="Sign In" Icon="ic_login" Route="LoginPage" ContentTemplate="{DataTemplate _v:AccountPage}" />
</FlyoutItem>

<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
    <ShellContent Title="Test1" Icon="ic_online_store" ContentTemplate="{DataTemplate _v:AccountPage}" />
    <ShellContent Title="Test2" Icon="ic_about_us" ContentTemplate="{DataTemplate _v:AccountPage}" />
</FlyoutItem>

您可以使用 MenuItem 在弹出窗口中显示项目。并使用 FlyoutItem 在底部标签栏中显示标签,而不将 FlyoutDisplayOptions 属性 设置为 AsMultipleItems

MenuItem 将在弹出窗口中显示项目,而 FlyoutItem 中的项目将显示在底部标签栏中。

 <MenuItem
    Command="{Binding AboutCommand}"
    Icon="tab_about.png"
    Text="Online Store" />

<FlyoutItem>
    <ShellContent Title="Dasboard" ContentTemplate="{DataTemplate _v:AccountPage}" />
    <ShellContent Title="Statistiche" ContentTemplate="{DataTemplate _v:AccountPage}" />
</FlyoutItem>

后面的代码:

public partial class AppShell : Xamarin.Forms.Shell
{
    public AppShell()
    {
        InitializeComponent();
        Routing.RegisterRoute("account", typeof(AccountPage));
        BindingContext = this;
    }
    public ICommand AboutCommand => new Command(async () => await NavigatedToAccount());

    async Task NavigatedToAccount()
    {
        await Shell.Current.GoToAsync("account");
        Shell.Current.FlyoutIsPresented = false;
    }

}