如何让标签栏在导航到详细信息页面时消失

问题描述 投票:0回答:1

我正在尝试实现以下简单的导航场景:

我有“Page 1”,它有一个选项卡栏,它允许导航到定义为全局路由的“DetailsPage”,并且仅显示一个后退按钮以导航回“Page 1”。该视频准确地显示了此场景:https://user-images.githubusercontent.com/74175405/229085788-05809927-904b-4503-8b33-c8a45204e7a2.mp4

我使用 Shell.SetTabarIsVisible 方法尝试了不同的方法,但没有成功,我在做了一些研究后尝试的最后一个方法似乎最有凝聚力的是分别在 FirstPage.xaml.cs 和 DetailsPage.xaml.cs 中执行此操作:

protected override void OnAppearing()
{
    base.OnAppearing();

    Shell.SetTabBarIsVisible(workoutSelectionPage, false); //This is Page 2, in page 1 I set true 
}

AppShell.xaml:

<TabBar>
    <Tab Title="Page 1">
        <ShellContent ContentTemplate="{DataTemplate local:FirstPage}"/>
    </Tab>
</TabBar>

AppShell.xaml.cs:

Routing.RegisterRoute("Page 2", typeof(DetailsPage));

这是一个非常基本的场景,所以我确信我错过了一些简单的东西,非常感谢任何输入,谢谢!

c# xaml navigation maui tabbar
1个回答
0
投票

我应该像把它放入 Ctor 一样简单:

public TestView(TestViewModel viewModel)
{
    BindingContext = _viewModel = viewModel;

    InitializeComponent();

    Shell.SetTabBarIsVisible(this, false);
}

也可以在 xaml 页面上设置它

<ContentPage
    x:Class="MauiTest.Views.TestView"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    Shell.NavBarIsVisible="False"
    Shell.TabBarIsVisible="False">
© www.soinside.com 2019 - 2024. All rights reserved.