Tabbed Page In Xamarin.Forms Using Fresh MVVM

In this tutorial, we will learn how create Tabbed Page in Xamarin.Forms using Fresh MVVM. We already learned how to create your master details page in my previous tutorials. If you are new to Fresh MVVM, you can read my previous article here.

Tabbed Page in Xamarin.Forms using Fresh MVVM 

Introduction

In this tutorial, we will learn how to create a Tabbed Page in Xamarin.Forms using Fresh MVVM. We already learned how to create a master details page in my previous tutorials. If you are new to Fresh MVVM, you can read my previous articles here:

Article on FreshMVVM

  1. MVVM Databinding in Xamarin.Forms using Fresh MVVM.
  2. Master Detail Page in Xamarin.Forms using Fresh MVVM.

Coding Part

Steps

I have split this part into 3 steps as in the following.

  • Step 1: Creating new Xamarin.Forms Projects.
  • Step 2: Setting up the plugin for Xamarin.Forms Application.
  • Step 3: Implementing Fresh MVVM.

Step 1

Create a new project by selecting New - Project - Xamarin Cross-Platform App and click "OK".

Tabbed Page in Xamarin.Forms using Fresh MVVM 

Select Android and iOS Platforms as shown below with Code-Sharing Strategy as PCL or .NET Standard and click "OK".

Tabbed Page in Xamarin.Forms using Fresh MVVM

 

Step 2

We will start coding for Fresh MVVM. Create a new Xamarin.Forms Project. Open NuGet Package Manager against the solution and do search for Fresh MVVM plugin or paste the following NuGet Installation.

Install-Package FreshMvvm -Version 2.2.3

Click "Install" to install this plugin against your PCL Project or .NET Standard Project.

Tabbed Page in Xamarin.Forms using Fresh MVVM 

Step 3

I have created two pages for creating a tabbed navigation as “Detail1Page” and “Detail2Page” with two respective page models “Detail1PageModel” and “Detail2PageModel”. We should follow the same set of rules we followed for our previous articles.

Set MainPage

To create a Fresh MVVM Tabbed Page as MainPage, we should use Fresh Tabbed Navigation Container with the following code.

  • Open xaml.cs or App.cs and set MainPage.
    1. var tabbedNavigation = new FreshTabbedNavigationContainer();  
    2. tabbedNavigation.AddTab<Detail1PageModel>("First Tab"null);  
    3. tabbedNavigation.AddTab<Detail2PageModel>("Second Tab"null);  
    4. MainPage = tabbedNavigation;  
  • Then Click Run, your Tabbed Page will be look like the below screenshot.
  • Here, we will not discuss about navigation between pages. If you want to know, you can see my previous article on Fresh MVVM.

Full code for App.xaml.cs

You can find the code for App.xaml.cs below

  1. public partial class App : Application  
  2. {  
  3.     public App()  
  4.     {  
  5.         try  
  6.         {  
  7.             InitializeComponent();  
  8.             var tabbedNavigation = new FreshTabbedNavigationContainer();  
  9.            tabbedNavigation.AddTab<Detail1PageModel>("First Tab"null);  
  10.            tabbedNavigation.AddTab<Detail2PageModel>("Second Tab"null);  
  11.            MainPage = tabbedNavigation;  
  12.         }  
  13.         catch (Exception ex)  
  14.         {  
  15.   
  16.         }  
  17.     }  
  18.   
  19.     protected override void OnStart()  
  20.     {  
  21.         // Handle when your app starts  
  22.     }  
  23.   
  24.     protected override void OnSleep()  
  25.     {  
  26.         // Handle when your app sleeps  
  27.     }  
  28.   
  29.     protected override void OnResume()  
  30.     {  
  31.         // Handle when your app resumes  
  32.     }  
  33. }  

Download Code

You can download the code from GitHub. If you have doubts, feel free to post a comment. If you like this article and it is useful to you, do like, share the article & star the repository on GitHub.