.Net Maui中的Shell导航

jv2fixgn  于 2023-04-07  发布在  Shell
关注(0)|答案(2)|浏览(237)

我在我的应用程序 shell 中使用标签栏,并希望我的第一页是一个自定义的启动画面,检查是否有一个用户对象,如果是,导航到主页,否则显示登录页面。
这是工作得很好,但我不能设置启动屏幕作为我的启动屏幕在 shell .当我添加到标签栏它是可见的选项在标签栏,如果删除启动屏幕不启动. enter image description here

<TabBar Route="tabbar">

        <Tab>
            <ShellContent
                ContentTemplate="{DataTemplate views:SplashPage}" />
        </Tab>

        <Tab Title="Home" Route="home">
            <Tab.Icon>
                <FontImageSource FontFamily="MaterialOutlined" Glyph="{x:Static md:Icons.Home}" />
            </Tab.Icon>
            <ShellContent ContentTemplate="{DataTemplate views:HomePage}" />
        </Tab>

        <Tab Title="Invoices" Route="invoices">
            <Tab.Icon>
                <FontImageSource FontFamily="MaterialOutlined" Glyph="{x:Static md:Icons.ShoppingCart}" />
            </Tab.Icon>
            <ShellContent ContentTemplate="{DataTemplate views:InvoicesPage}" />
        </Tab>

        <Tab Title="Customers" Route="customers">
            <Tab.Icon>
                <FontImageSource FontFamily="MaterialOutlined" Glyph="{x:Static md:Icons.Person}" />
            </Tab.Icon>
            <ShellContent ContentTemplate="{DataTemplate views:CustomersPage}" />
        </Tab>

    </TabBar>

选项卡栏中显示了一个空的部分。如何启用启动屏幕作为入口点,而不将其显示在选项卡栏中?

xwbd5t1u

xwbd5t1u1#

对于SplashPage的场景,我根本不会使用Shell。只需在App构造函数中像这样启动程序:

public App()
{
    InitializeComponent();
    this.MainPage = new LoadAppPage();
}

LoadAppPage只是一个普通的ContentPage。在那里你可以完成你的应用程序的所有初始化逻辑,显示一些等待的UI,检查用户,也许显示一个登录页面。
当你完成了LoadAppPage中的所有逻辑后,你可以从那里导航到你的应用的Shell,只需替换你的应用的MainPage

Application.Current.MainPage = new ApplicationShell();
bvuwiixz

bvuwiixz2#

<ShellItem Route="SplashPage">
    <ShellContent ContentTemplate="{DataTemplate views:SplashPage}"/>
</ShellItem>

<TabBar>
    ...

像这样构造你的Shell XAML。

相关问题