简体   繁体   English

如何在Xamarin.Forms中创建类似于Facebook应用程序的标签页

[英]How to create tabbed page in Xamarin.Forms similar to that of Facebook app

I am working with Xamarin.Forms and I would like to create a navigation method similar to that of the Facebook app and also other newer versions of different apps. 我正在使用Xamarin.Forms ,我想创建一个类似于Facebook应用程序的导航方法以及其他不同应用程序的更新版本。 Here are two pictures, one of Facebook app on Android and the other is of KakaoTalk, also on Android . 这是两张图片,一张是Android上的Facebook应用程序,另一张是KakaoTalk,也是在Android上

Android上的Facebook应用

Android上的KakaoTalk应用程序

I've tried several different ways to implement this. 我已经尝试了几种不同的方法来实现它。 For example I wrapped the MainPage ( TabbedPage ) inside a NavigationPage . 例如,我将MainPage( TabbedPage )包装在NavigationPage中 I also tried wrapping the MainPage ( ContentPage ) inside a NavigationPage then calling 我还尝试在NavigationPage中包装MainPage( ContentPage )然后调用

PushAsync(new TabbedPage());

inside the MainPage via the Navigation property. 通过Navigation属性在MainPage内部。 I also tried wrapping the children of the MainPage ( TabbedPage ) inside separate NavigationPage s. 我还尝试将MainPage( TabbedPage )的子项包装在单独的NavigationPage中 None of these attempts resulted in the desired effect. 这些尝试都没有产生预期的效果。

I would like the following to happen. 我希望以下情况发生。 When a user taps on a Button or something that navigates to another page I'd like a ContentPage to pop in front of everything (tab bar included) except for the Navigation bar (or Action Bar). 当用户点击按钮或导航到另一个页面的东西时,我希望ContentPage弹出所有内容(包括标签栏), 导航栏 (或操作栏)除外。 Obviously this happens via the PushAsync() method which also results in a small back arrow appearing in the Nav bar. 显然,这通过PushAsync()方法发生,这也导致导航栏中出现一个小的后箭头。 My understanding is that a PushAsync() call pushes the chosen page onto the navigation stack provided by the NavigationPage . 我的理解是PushAsync()调用将所选页面推送到NavigationPage提供的导航堆栈。 Therefore if a TabbedPage is wrapped inside a NavigationPage a new ContentPage would not be able to pop in front of the tabs like in the two applications mentioned above. 因此,如果TabbedPage被包装在NavigationPage中 ,则新的ContentPage将无法像在上面提到的两个应用程序中一样弹出选项卡。

This, plus the fact that the tab bars of said apps don't get inside the ActionBar (in Android) in landscape mode leads me to believe that what I'm trying to achieve is best done not using TabbedPage but something that acts like a tab bar, eg a horizontal stack of Buttons perhaps. 这个以及所述应用程序的标签栏没有进入横向模式的ActionBar (在Android中)这一事实让我相信我想要实现的最好不要使用TabbedPage,而是像标签栏,例如也许是水平的按钮堆栈。

Has anyone implemented this correctly and in an elegant way using Xamarin.Forms? 有没有人使用Xamarin.Forms以正确的方式正确实现这一点? So again, I would like to make this tab like navigation with the tabs staying underneath the ActionBar in landscape mode and a new Page appearing in front of the tabs (hiding them) when pushed onto the navigation stack. 所以再一次,我想让这个标签像导航一样,标签停留在横向模式下的ActionBar下面,当推到导航堆栈上时,新标签出现在标签前面(隐藏它们)。 Do you think this can be done with Custom Renderer s? 你认为这可以用Custom Renderer来完成吗? Of course in iOS these are done with tabs but in Android I'm not sure. 当然在iOS中这些都是使用标签完成的,但在Android中我不确定。

What I would like is not necessarily code examples, but a best practice on this issue. 我想要的不一定是代码示例,而是这个问题的最佳实践。 So again, this is in Xamarin.Forms with a common PCL project and an Android and iOS project. 再次,这是在Xamarin.Forms与一个常见的PCL项目和一个Android和iOS项目。 Thank you in advance for your answers and advices! 提前感谢您的答案和建议!

PS: I've obviously searched this site before (Google as well) but I've found no real articles on this issue. PS:我之前显然已经搜索过这个网站(谷歌也是如此),但我没有找到关于这个问题的真实文章。

My understanding is that a PushAsync() call pushes the chosen page onto the navigation stack provided by the NavigationPage. 我的理解是PushAsync()调用将所选页面推送到NavigationPage提供的导航堆栈。 Therefore if a TabbedPage is wrapped inside a NavigationPage a new ContentPage would not be able to pop in front of the tabs like in the two applications mentioned above. 因此,如果TabbedPage被包装在NavigationPage中,则新的ContentPage将无法像在上面提到的两个应用程序中一样弹出选项卡。

This is not true actually. 事实并非如此。 According to Xamarin API Doc , the Navigation property is context-aware, ie it will find all its parents until there is a NavigationPage . 根据Xamarin API DocNavigation属性是上下文感知的,即它会找到所有父项,直到有一个NavigationPage

In Android, only one NavigationPage is allowed and therefore even you call PushAsync() inside the TabbedPage , it will still push via your wrapping NavigationPage . 在Android中,只允许一个 NavigationPage ,因此即使你在TabbedPage调用PushAsync() ,它仍将通过你的包装NavigationPage推送。

You can create a custom controller using the grid. 您可以使用网格创建自定义控制器。 it will remove the hassle of writing custom renderers. 它将消除编写自定义渲染器的麻烦。

I have used ToolbarItems order=primary for navigation bar menu button and ToolbarItems order=secondary for tab bar on top.I have PCL the code written is in XAML. 我使用了ToolbarItems order = primary用于导航栏菜单按钮,而ToolbarItems order = secondary用于标签栏。我有PCL编写的代码是在XAML中。 :) :)

http://codeworks.it/blog/?p=232 http://codeworks.it/blog/?p=232

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM