to separate the NavigationPage from the tab page to be displayed, and that when navigating there is no

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

我正在使用Prism库创建Xamarin表单应用程序,页面结构如下。

  • MyTabbedPage : TabbedPage
  • MyFirstPage : ContentPage (它是MyTabbedPage的第一个孩子)
  • MySecondPage : ContentPage (单独的页面,不是MyTabbedPage的子页面)

我的目标是:应用程序启动,用户在 "我的第一页 "中看到标签和列表视图。当用户点击任何一个项目时,应该显示 "我的第二页",并且用户可以在导航栏中看到返回按钮,这将使他返回到 "我的第一页"。

以下是我尝试做的例子和得到的结果。

1.

//when app started
_prismNavService.NavigateAsync(new System.Uri(@"/MyTabbedPage?selectedTab=MyFirstPage", UriKind.Absolute));
//when item in listview tapped
_prismNavService.NavigateAsync("MySecondPage", parameters: param);

结果显示第二页,但顶部没有导航栏。

2.

_prismNavService.NavigateAsync(new System.Uri(@"/MyTabbedPage?selectedTab=MyFirstPage", UriKind.Absolute));

_prismNavService.NavigateAsync("NavigationPage/MySecondPage", parameters: param);

结果: 第二页有导航栏,设备的后退按钮返回到 "我的第一页",但导航栏上没有后退按钮(左箭头)。

3.

_prismNavService.NavigateAsync(new System.Uri(@"/MyTabbedPage?selectedTab=MyFirstPage", UriKind.Absolute));

_prismNavService.NavigateAsync("MySecondPage", param, false); //useModalNavigation : false

结果第二页不显示

4.

_prismNavService.NavigateAsync(new System.Uri(@"/MyTabbedPage?selectedTab=MyFirstPage", UriKind.Absolute));
When tapped:
_prismNavService.NavigateAsync("MySecondPage", param, true);

结果:第二页有导航栏,设备的后退按钮返回到 "我的第一页",但导航栏上没有后退按钮(左箭头)。

5.

_prismNavService.NavigateAsync(new System.Uri(@"/NavigationPage/MyTabbedPage/MyFirstPage", UriKind.Absolute));
_prismNavService.NavigateAsync("MySecondPage", param, false); //useModalNavigation : false

结果第二页有导航栏,设备的后退键从App中消失,导航栏上没有后退键(左箭头)。

6.

_prismNavService.NavigateAsync(new System.Uri(@"/MyTabbedPage/NavigationPage/MyFirstPage", UriKind.Absolute));
_prismNavService.NavigateAsync("MySecondPage", param, false); //useModalNavigation : false

结果: 不显示第二页

谁能解释一下应该实现哪种结构和导航来使其工作?

xamarin.forms prism back-button navigationbar tabbedpage
1个回答
0
投票

你需要把显示在标签页中的页面放在NavigationPage中,然后当你从标签页导航到子页面时,确保你这样做是为了让它添加到堆栈中,而不是在它上面弹出一个模态。

例如,如果你使用查询字符串动态创建Tabs

await NavigationService.NavigateAsync("MainPageTabbed?createTab=NavigationPage|ViewsA&createTab=NavigationPage|ViewB");

当从选项卡ViewA导航到子页面时。

await NavigationService.NavigateAsync("SomeChildPage");

确保在动态创建标签页时,在路径的开始处使用一个管道来导航。

同样,如果你在XAML中静态地创建标签页,你也可以实现同样的目标。

<TabbedPage>
 <NavigationPage Title="View A">
    <x:Arguments>
        <local:ViewA Title="View A" />
    </x:Arguments>
 </NavigationPage>
</TabbedPage>
© www.soinside.com 2019 - 2024. All rights reserved.