read

Tabbed Pages are a common pattern that regular mobile App users are familiar with. At it’s simplest it is just a collection of pages tied together by a toolbar menu at the top or bottom of the screen. I say top or bottom because iOS, Android and WP do things differently here, and Xamarin.Forms does it’s best to keep true to the platforms. On Android it uses a bar at the top, for iOS the tab bar at the bottom, and on Windows Phone it uses a Pivot control.

TabbedPages

A TabbedPage is essentially a container object for other page types and provides a way of navigating between it’s child pages.   About the simplest possible implementation in code would be:

It is also possible to bind the ItemsSource property to create the list of pages, like this:

To be honest honest I don’t see many situations where you would want to bind a set of Tabbed Pages. Normally the tabs would be a group of well known pages which are statically defined. Additionally you would not want to define the pages inline, but rather reference other pages in your application. So let’s see how we do that using Xaml

First we create some normal, run of the mill pages that we want to show in the tabs, for example:

Now we create our MainTabContainer.xaml page. We just do this by creating a normal XAML content page, but then change it from being a content page to being a TabbedPage (remember to change the type in the code behind .cs file too. Then we add the pages we want tabs for in the TabbedPage.Childrens collection – (Note we have added the mypages namespace at the top so we can reference the pages)

Adding Icons

We can add Icons to the tab pages, but with the standard Xamarin.Forms implementation this only works for iOS.  This kind of makes sense, because WP does not have images on pivots, and neither does Android Tabs.  To add the icons it’s a simple matter of setting the icon property.  Remembering that the icons need to be included in the platform specific iOS project to work.  The icons need to have a transparent background with a white foreground.   Apple has guidelines for creating icons here.  To implement, just set the Icon property:

TabBarIcons

More than 5 Tabs

One of the design limitations decisions in iOS is when there are more than 5 tabs, it goes into an overflow mode with “more…” like this :
iOS Simulator Screen Shot 1 Mar 2015 2.05.48 pm
The user can navigate to any of the tabs from there, or click the Edit button at the top to reorganize the tabs on the page.  It’s a pretty cool feature, but there is not much control over it.
iOS Simulator Screen Shot 1 Mar 2015 2.05.57 pm (1)

Android and Windows Phone do not have this functionality. On Windows Phone it just adds more pivot pages which the user can scroll across, and on Android the tab bar at the top becomes scrollable (although it does not implement swipe across pages).

In summary the TabbedPage implemtation in Xamarin.Forms is basic yet totally sufficient for simple tabbed navigations.

You can find the source code from this post over on my github.

Next up, I’ll have a look a bit deeper into Tabbed pages and look at adding navigation pages inside the TabbedPage. Till then, take care.

Kym

Mobile, Xamarin, Windows Store Apps, Agile -- I love 'em all! Check out more


Published on

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Kym Phillpotts

I write about Xamarin Forms, mobile development or whatever else I might be concentrating on.

Back to Home