【问题标题】:how to display TabBar on all shell child pages in single page app如何在单页应用程序的所有 shell 子页面上显示 TabBar
【发布时间】:2021-09-24 07:37:14
【问题描述】:

我想使用 Shell 创建一个单页应用程序,其中每个页面都包含一个类似于 [Back] [Title] [Settings] 的标题栏。

如果我有这样的页面序列 [登录] -> [主页] -> [设置],当我在它们之间导航时,我希望在每个页面上看到相同的标题栏。

我为标题栏设置了一个 ControlTemplate,并将其添加到每个 xaml 页面,如下所示:=

<Shell.TitleView>
        <TemplatedView ControlTemplate="{StaticResource TopBar}" />
</Shell.TitleView>

我在 Shell 构造函数中将登录和主页注册为路由。

public AppShell()
{
    InitializeComponent();
    Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));
    Routing.RegisterRoute(nameof(SettingsPage), typeof(SettingsPage));
}

在 Shell.xaml 我有这样注册的登录页面:-

   <TabBar>
        <Tab>
            <ShellContent ContentTemplate="{DataTemplate views:LoginPage}" Route="LoginPage" />
        </Tab>
    </TabBar>

当我运行应用程序时,TitleView 会显示在登录页面上。然后我单击按钮登录,我被带到主页,但 TitleView 不见了。如果通过单击 TitleView 图标导航到“设置”页面,它也会丢失。

设置页面和主页都设置了Shell.TabBarIsVisible="True"

我在命令中这样导航

await Shell.Current.GoToAsync($"{nameof(Views.SettingsPage)}");

谁能告诉我这是否可行,如果可以,请问我做错了什么?

谢谢

【问题讨论】:

    标签: xamarin xamarin.forms xamarin.forms.shell


    【解决方案1】:

    答案是不要将Shell.PresentationMode="ModalAnimated" 错误地添加到您要导航的页面。呵呵!

    【讨论】:

      猜你喜欢
      • 2012-05-28
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多