【问题标题】:Move tabs to bottom with Xamarin.Forms Shell使用 Xamarin.Forms Shell 将选项卡移动到底部
【发布时间】:2020-04-08 00:49:15
【问题描述】:

我正在尝试将我的 Xamarin.Forms 应用从带有 Menu 和 TabPage 的 MasterDetailPage 转换为新的 Xamarin.Forms Shell。

我正在尝试将标签移到底部。我还希望它们看起来与 TabPage 相同。使用基本的 Shell XAML 布局可以实现此事件吗?

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:views="clr-MyApp.Views"
       xmlns:volDash="clr-MyApp.Views.VolDash"
       x:Class="MyApp.AppShell">
    <FlyoutItem Title="Dashboard 1" FlyoutDisplayOptions="AsSingleItem">
        <Tab>
            <ShellContent Title="Signups" Icon="ic_assignment.png">
                <volDash:SignupsPage />
            </ShellContent>
            <ShellContent Title="Events" Icon="ic_event.png">
                <volDash:AreasPage />
            </ShellContent>
            <ShellContent Title="Mailbox" Icon="ic_mail_outline.png">
                <volDash:MailboxPage />
            </ShellContent>
            <ShellContent Title="Rankings" Icon="fa_trophy.png">
                <volDash:MyRankingsPage />
            </ShellContent>
            <ShellContent Title="Videos" Icon="ic_ondemand_video.png">
                <volDash:TrainingVideoCategoriesPage />
            </ShellContent>
        </Tab>
    </FlyoutItem>
    <FlyoutItem Title="Dashboard 2" FlyoutDisplayOptions="AsSingleItem">
        <Tab>
            <ShellContent Title="Tab 1" Icon="ic_assignment.png">
                <volDash:SignupsPage />
            </ShellContent>
            <ShellContent Title="Tab 2" Icon="ic_event.png">
                <volDash:AreasPage />
            </ShellContent>
        </Tab>
    </FlyoutItem>
    <ShellContent Title="Account" Icon="ic_account_box_white.png">
        <views:AccountPage />
    </ShellContent>
</Shell>

我发现的另一种方法是从 FlyoutItem 调用 TabPage。选项卡正确显示在底部。然而,我最终在顶部有一个丑陋的差距。

<?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:views="clr-MyApp.Views"
       xmlns:volDash="clr-MyApp.Views.VolDash"
       x:Class="MyApp.AppShell">
    <FlyoutItem Title="Volunteer Dashboard" FlyoutDisplayOptions="AsSingleItem">
        <ShellContent Title="Videos" Icon="ic_account_box_white.png">
            <views:VolunteerDashboardPage />
        </ShellContent>
    </FlyoutItem>
    <FlyoutItem Title="Organizer Dashboard" FlyoutDisplayOptions="AsSingleItem">
        <ShellContent Title="Videos" Icon="ic_account_box_white.png">
            <views:OrganizerDashboardPage />
        </ShellContent>
    </FlyoutItem>
    <ShellContent Title="Account" Icon="ic_account_box_white.png">
        <views:AccountPage />
    </ShellContent>
</Shell>

【问题讨论】:

    标签: xamarin.forms xamarin.forms.shell


    【解决方案1】:

    您不能使用 Tab 样式来定义 FlyoutItem 。 Shell 应用中的 Tab 会与 Tabbed Page 的 tab 不同。

    Tab and ShellContentShell Application 中定义如下。

    • Tab,表示分组内容,可通过底部标签导航。每个Tab 对象都是FlyoutItem 对象或TabBar 对象的子对象。
    • ShellContent,代表应用程序中的ContentPage 对象。每个ShellContent 对象都是 Tab 对象的子对象。当Tab 中存在多个ShellContent 对象时,这些对象将可以通过顶部选项卡进行导航。

    因此,您可以在此处修改共享代码进行如下尝试:

    <?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:views="clr-MyApp.Views"
           xmlns:volDash="clr-MyApp.Views.VolDash"
           x:Class="MyApp.AppShell">
        <FlyoutItem Title="Dashboard 1" FlyoutDisplayOptions="AsSingleItem">
    
                <ShellContent Title="Signups" Icon="ic_assignment.png">
                    <volDash:SignupsPage />
                </ShellContent>
                <ShellContent Title="Events" Icon="ic_event.png">
                    <volDash:AreasPage />
                </ShellContent>
                <ShellContent Title="Mailbox" Icon="ic_mail_outline.png">
                    <volDash:MailboxPage />
                </ShellContent>
                <ShellContent Title="Rankings" Icon="fa_trophy.png">
                    <volDash:MyRankingsPage />
                </ShellContent>
                <ShellContent Title="Videos" Icon="ic_ondemand_video.png">
                    <volDash:TrainingVideoCategoriesPage />
                </ShellContent>
            
        </FlyoutItem>
        <FlyoutItem Title="Dashboard 2" FlyoutDisplayOptions="AsSingleItem">
          
                <ShellContent Title="Tab 1" Icon="ic_assignment.png">
                    <volDash:SignupsPage />
                </ShellContent>
                <ShellContent Title="Tab 2" Icon="ic_event.png">
                    <volDash:AreasPage />
                </ShellContent>
          
        </FlyoutItem>
        <ShellContent Title="Account" Icon="ic_account_box_white.png">
            <views:AccountPage />
        </ShellContent>
    </Shell>
    

    【讨论】:

    • 使用 Shell 是否可以在 Flyout 和底部 Tabbar 中有不同的项目?
    • @ThamaraiT 嗨,您是指不同的 FlyoutItems 吗?如果是这样,当然。
    • 考虑 Flyout 有 'About Us'、'Contact Us' 和 'SignIn / SignOut' Shell 对象...同时底部 Tabbar 有 'Home'、'Cart' 和 'Profile' shell 对象。有可能吗?
    • 有关我所要求的详细信息,请查看stackoverflow.com/questions/65085818/…
    • @ThamaraiT 好的,我会检查的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    • 2014-05-26
    • 2023-03-16
    相关资源
    最近更新 更多