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

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.

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. protected override void OnStart()
  18. {
  19. // Handle when your app starts
  20. }
  21. protected override void OnSleep()
  22. {
  23. // Handle when your app sleeps
  24. }
  25. protected override void OnResume()
  26. {
  27. // Handle when your app resumes
  28. }
  29. }

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.