Xamarin Prism Android 不会丢失 TabbedPage 或更改 NavigationPage [英] Xamarin Prism Android won't lose TabbedPage or change NavigationPage

查看:85
本文介绍了Xamarin Prism Android 不会丢失 TabbedPage 或更改 NavigationPage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用 NavigationPageTabbedPage 的项目在 iOS 中按预期工作,但在 Android 中不工作(Xamarin Forms (2.3.3.193) with Prism (6.3.0)).

We have a project using a NavigationPage and TabbedPage working as expected in iOS but not Android (Xamarin Forms (2.3.3.193) with Prism (6.3.0)).

我已经建立了一个示例项目,可在此处使用.

这个应用程序包含三个页面,它们嵌套在一个 NavigationPage 和一个 TabbedPage(APage、BPage 和 CPage)中,第四个页面应该丢失 TabbedPage 并保留一个 NavigationPage(B1Page 可通过 BPage 获得).

This application consists of three pages which are nested in a NavigationPage and a TabbedPage (APage, BPage and CPage) and a fourth page which should lose the TabbedPage and keep a NavigationPage (B1Page is available through BPage).

NavigationService.NavigateAsync("NavigationPage/LayoutTabbedPage/APage");

在 iOS 上使用导航和标签栏打开 APage在 Android 上看起来不错

BPage 在导航栏上有一个添加"按钮在Android上看起来不错

点击添加"应该会打开 B1Page.这仍然有导航栏(带有保存"按钮而不是添加")但没有标签栏.

Clicking 'Add' should open B1Page. This still has the navigation bar (with a 'Save' button instead of 'Add') but no tab bar.

m_navigationService.NavigateAsync("NavigationPage/LayoutTabbedPage/BPage/B1Page");

但是在 Android B1Page 上,标签栏仍然存在并且与原始导航栏一样(使用添加按钮而不是保存按钮).

But on Android B1Page the tab bar remains and as does the original navigation bar (with the Add button instead of Save).

我在导航方面做错了什么,导致这些不一致?

Is there something wrong I'm doing with navigation which makes these inconsistent?

推荐答案

是的,您的导航有问题.首先,如果您想在 TabbedPage 中导航并保留您的标签,您需要将您的 Tab 包装在 NavigationPage 中,而不是将 TabbedPage 包装在 NavigationPage 中.像这样:

Yes, you have issues with your navigation. First off, if you want to navigate within a TabbedPage and keep your tabs, you need to wrap your Tab in a NavigationPage, not the TabbedPage in a NavigationPage. Something like this:

<代码><NavigationPage Title="B"><x:参数><local:BPage/></x:参数></NavigationPage>

这将允许您在实际标签中导航.

This will allow yo to navigate within the actual Tab.

如果这不是您想要做的,那么将您的 tabbedPage 包裹在导航页面中,然后当您导航到 B1Page 时,使用NavigateAsync("B1Page", usemodalNavigation: false)"强制异步导航调用.这会将您从选项卡式页面弹出,但将您保留在带有后退箭头和工具栏项的导航页面内.

If this is not what you want to do, then keep your tabbedPage wrapped in a navigation page and then when you navigate to B1Page force an async nav call using 'NavigateAsync("B1Page", usemodalNavigation: false)`. This will bounce you out of the tabbed page but keep you within the navigation page with the back arrow and toolbar item.

其次,您的导航 Uri 一团糟.Prism 中的导航与您调用它的位置有关.

Secondly, your navigation Uri's are a mess. Navigation in Prism is relative to where you are calling it.

当您调用 m_navigationService.NavigateAsync("NavigationPage/LayoutTabbedPage/BPage/B1Page"); 时,您将所有这些页面再次推送到导航堆栈上.如果您在 Android 上按后退按钮,您就会明白我的意思.

When you make this call m_navigationService.NavigateAsync("NavigationPage/LayoutTabbedPage/BPage/B1Page"); you are pushing all those pages onto the navigation stack again. If you hit your back button on Android you will see what I mean.

您所要做的就是从 BPageViewModel 调用 NavigateAsync("B1Page");.

All you have to do is from BPageViewModel call NavigateAsync("B1Page");.

这应该能让你指明正确的方向.

That should get you pointed in the right direction.

这篇关于Xamarin Prism Android 不会丢失 TabbedPage 或更改 NavigationPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆