Attractive customizable Tabs with Xamarin Community Toolkit


Isn't it fun,

to instantly listen to a blog on the go? PLAY !

 
 

customizable Tabs with Xamarin

Table of Content

What is Xamarin?

Xamarin is an open-source platform and a cross-platform development technology using which we can build an application in Android, iOS, and Windows phones. In Xamarin, for iOS, Android, and Windows phone we can build a native user interface using a single code base with C#.


Tabbed Page

In Tabbed Page there are multiple pages or tabs so we can easily move one page to another page by just clicking on tabs. This page can allow navigation between pages or tabs. On the Tabbed page, the user can navigate from one page to another page with just a single click. In Xamarin, the tabbed page has many child pages we can see that pages in the click of their tabs, each tab has its own content and has its own title. You can customize the page and add the data that you need on the page. Tabbed pages are used when we want to move one page to another page on the same screen.

In android, all tabs are displayed at the top of the screen and their contents are displayed below same as in iOS all tabs are displayed at bottom of the screen, and their content displays above and on the Universal Window Platform (UWP) all the tabs are displayed at the top of the screen and their contents are displayed below.

The tabbed page contains the below properties.

  1. SelectedTabColor: This property is used to display a color when a tab is selected.
  2. UnselectedTabColor: This property is used to display a color when a tab is unselected.
  3. BarBackgroundColor: This property is used to display the background color of the tab bar.
  4. BarTextColor: This property is used to display the color of text on the tab bar.

Now, let's see how to use tabbed pages in different ways.

Step: 1

Open Visual Studio and select Xamarin project.

Image: Create a Xamarin project
 

Image: Select template and platform.



Step: 2

Now, you need to change ContentPage to TabbedPage in MainPage.Xaml then add the below code or you can create your design.




    
        

    
        

    
        

    
        


Output:

Image: Tabbed Page Example
 

This is the simple way to use a tabbed page in our project. Now, we can see the different ways to create a tabbed page in our project.

After the creation of your project just right-click your project and click Add -> New item -> Xamarin.Forms -> Tabbed Page -> change the page name as your requirement and click to add button.

When you click to add button, you will see some below code in your project.



  
  
  
  

This is the default tabbed page example now we can modify it as your requirement.

There are two ways to display the child page on the main tabbed page.

  1. 1.You can directly code multiple content pages in your main tabbed page.
  2. 2.And you can use the reference of another page as a child of the main tabbed page.


    
    
        
            
                
                    
            
            
        
    
    
        
            
                
                    
            
            
        
    

This is the first way to use the tabbed page in our main tabbed page. You just need to add a content page in your main tabbed page and you can create a tabbed page. On your main XAML page, you just need to add a button that navigates the tabbed page.

MainWindow.XAML


    
    
MainWindow.XAML.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace TabbedPageExample
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Clicked(object sender, EventArgs e)
        {
            Navigation.PushModalAsync(new NavigationPage());
        }
    }
}

Planning to Hire Xamarin App Development Company ?

Your Search ends here.


When you click the button that navigates to your main tabbed page. Second option to use the reference of another page in the tabbed page.



    
    
    
        
            
                
                    
            
            
        
    
    
        
            
                
                    
            
            
        
    

We can add a child page in the tabbed page using the reference of the page (i.e. ).



    
    
        
        
            
                
                    
                        
                
                
            
        
        
            
                
                    
                        
                
                
            
        
    

Output:

Image: Button that navigates to a tabbed page
 

Image: Tabbed page example
 

The output of using a reference of child page and direct use of the content page.

Image: Using the reference of a child page
 

We can also set a tab bar at the bottom of the screen using the TabbedPage.Children.

Output:

Image: Bottom tab bar example

Conclusion

In this blog, we learned how to navigate from one page to another page using a single click. The main use of the tabbed page is to make easier navigation between the pages.

Attractive customizable Tabs with Xamarin Community Toolkit

customizable Tabs with Xamarin

Table of Content

What is Xamarin?

Xamarin is an open-source platform and a cross-platform development technology using which we can build an application in Android, iOS, and Windows phones. In Xamarin, for iOS, Android, and Windows phone we can build a native user interface using a single code base with C#.


Tabbed Page

In Tabbed Page there are multiple pages or tabs so we can easily move one page to another page by just clicking on tabs. This page can allow navigation between pages or tabs. On the Tabbed page, the user can navigate from one page to another page with just a single click. In Xamarin, the tabbed page has many child pages we can see that pages in the click of their tabs, each tab has its own content and has its own title. You can customize the page and add the data that you need on the page. Tabbed pages are used when we want to move one page to another page on the same screen.

In android, all tabs are displayed at the top of the screen and their contents are displayed below same as in iOS all tabs are displayed at bottom of the screen, and their content displays above and on the Universal Window Platform (UWP) all the tabs are displayed at the top of the screen and their contents are displayed below.

The tabbed page contains the below properties.

  1. SelectedTabColor: This property is used to display a color when a tab is selected.
  2. UnselectedTabColor: This property is used to display a color when a tab is unselected.
  3. BarBackgroundColor: This property is used to display the background color of the tab bar.
  4. BarTextColor: This property is used to display the color of text on the tab bar.

Now, let's see how to use tabbed pages in different ways.

Step: 1

Open Visual Studio and select Xamarin project.

Image: Create a Xamarin project
 

Image: Select template and platform.



Step: 2

Now, you need to change ContentPage to TabbedPage in MainPage.Xaml then add the below code or you can create your design.




    
        

    
        

    
        

    
        


Output:

Image: Tabbed Page Example
 

This is the simple way to use a tabbed page in our project. Now, we can see the different ways to create a tabbed page in our project.

After the creation of your project just right-click your project and click Add -> New item -> Xamarin.Forms -> Tabbed Page -> change the page name as your requirement and click to add button.

When you click to add button, you will see some below code in your project.



  
  
  
  

This is the default tabbed page example now we can modify it as your requirement.

There are two ways to display the child page on the main tabbed page.

  1. 1.You can directly code multiple content pages in your main tabbed page.
  2. 2.And you can use the reference of another page as a child of the main tabbed page.


    
    
        
            
                
                    
            
            
        
    
    
        
            
                
                    
            
            
        
    

This is the first way to use the tabbed page in our main tabbed page. You just need to add a content page in your main tabbed page and you can create a tabbed page. On your main XAML page, you just need to add a button that navigates the tabbed page.

MainWindow.XAML


    
    
MainWindow.XAML.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace TabbedPageExample
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Clicked(object sender, EventArgs e)
        {
            Navigation.PushModalAsync(new NavigationPage());
        }
    }
}

Planning to Hire Xamarin App Development Company ?

Your Search ends here.


When you click the button that navigates to your main tabbed page. Second option to use the reference of another page in the tabbed page.



    
    
    
        
            
                
                    
            
            
        
    
    
        
            
                
                    
            
            
        
    

We can add a child page in the tabbed page using the reference of the page (i.e. ).



    
    
        
        
            
                
                    
                        
                
                
            
        
        
            
                
                    
                        
                
                
            
        
    

Output:

Image: Button that navigates to a tabbed page
 

Image: Tabbed page example
 

The output of using a reference of child page and direct use of the content page.

Image: Using the reference of a child page
 

We can also set a tab bar at the bottom of the screen using the TabbedPage.Children.

Output:

Image: Bottom tab bar example

Conclusion

In this blog, we learned how to navigate from one page to another page using a single click. The main use of the tabbed page is to make easier navigation between the pages.