【问题标题】:Hiding Top Navigations Bar in one of the shell tabs在其中一个 shell 选项卡中隐藏顶部导航栏
【发布时间】:2023-01-24 19:19:44
【问题描述】:

我一直试图在其中一个 shell 选项卡中隐藏顶部导航栏,但没有成功。

我尝试关注此 Tutorial 但没有成功(可能已过时?)。

这是我的代码:

<Shell
    x:Class="Smogon_MAUIapp.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:Smogon_MAUIapp"
    Shell.FlyoutBehavior="Disabled">


    <!--Main Page-->
    <TabBar>

        <Tab Icon="Resources/navbar/smogon.png" Shell.NavBarIsVisible="False" >
            <ShellContent
                Shell.NavBarIsVisible="False"
                NavigationPage.HasNavigationBar="False"
                ContentTemplate="{DataTemplate local:Pages.MainPage}" 
                Route="MainPage">
            </ShellContent>
            <ShellContent
                Shell.NavBarIsVisible="False"
                NavigationPage.HasNavigationBar="False"
                ContentTemplate="{DataTemplate local:Pages.Forum}"
                Route="Forum"/>
            <ShellContent
                Shell.NavBarIsVisible="False"
                NavigationPage.HasNavigationBar="False"
                ContentTemplate="{DataTemplate local:Pages.SubForum}"
                Route="SubForum"/>
            <ShellContent
                Shell.NavBarIsVisible="False"
                NavigationPage.HasNavigationBar="False"
                ContentTemplate="{DataTemplate local:Pages.Thread}"
                Route="Thread"/>
        </Tab>

        <Tab Icon="Resources/Images/search.png" Shell.NavBarIsVisible="False">
            <ShellContent
                ContentTemplate="{DataTemplate local:Pages.Search}" 
                Route="Search">
            </ShellContent>
        </Tab>

        <Tab Icon="Resources/Images/snorlax.png" Shell.NavBarIsVisible="False">
            <ShellContent
                ContentTemplate="{DataTemplate local:Pages.Profile}" 
                Route="Profile" />
        </Tab>

        <Tab Icon="Resources/Images/showdown.png" Shell.NavBarIsVisible="False">
            <ShellContent
                ContentTemplate="{DataTemplate local:Pages.Showdown}" 
                Route="Showdown" />
        </Tab>

    </TabBar>

</Shell>

和背后的代码:

public partial class AppShell : Shell
{
    public AppShell()
    {
        Routing.RegisterRoute("Home", typeof(MainPage));
        Routing.RegisterRoute("Forum", typeof(Forum));
        Routing.RegisterRoute("SubForum", typeof(SubForum));
        Routing.RegisterRoute("Thread", typeof(Smogon_MAUIapp.Pages.Thread));
        Routing.RegisterRoute("Search", typeof(Search));
        Routing.RegisterRoute("Profile", typeof(Profile));
        Routing.RegisterRoute("ShowDown", typeof(Showdown));

        InitializeComponent();
    }
}

这是我得到的和我想要的截图: Gotten result Vs Wanted one

帮助将不胜感激! =)

我尝试删除 shell 中我的一个选项卡的顶部栏。但我只能删除标题,而栏仍然存在。

【问题讨论】:

  • 您是否尝试过在页面的 XAML 根元素中设置 Shell.NavBarIsVisible="False"
  • 我只是在标签栏和外壳上都做了,没有成功
  • 不,在您用作 ContentTemplate 的页面的 XAML 中,例如论坛.xaml

标签: maui maui-shell


【解决方案1】:

在您的页面中,例如你的论坛.xaml,你可以设置Shell.NavBarIsVisible="False"隐藏导航栏,例如:

<ContentPage
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    Shell.NavBarIsVisible="False">
    <!-- ... -->
</ContentPage>

这必须在ContentPage 中完成。

边注:使用Shell 时不支持NavigationPage,因此您可以安全地从Shell 定义中删除NavigationPage.HasNavigationBar="False",因为它已过时。

【讨论】:

    猜你喜欢
    • 2016-03-28
    • 2017-12-27
    • 2019-01-19
    • 2019-09-11
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    相关资源
    最近更新 更多