Xamarin.Forms Project Architecture

Introduction

Xamarin.Forms are used to create cross platform applications like on Android, iOS or Windows mobile. Therefore, we are going to learn how to create the Xamarin.Forms solution from scratch. Xamarin.Forms solutions consist of different projects such as Portable, Android, iOS and Windows. Here, we will put our business logic inside the portable code and some platform specific code inside the Android/iOS/Windows project.

Solution

Description of the architecture is shown below.

To create Xamarin.Forms solution, you need to follow the steps given below.

Step 1

Open Visual Studio and create New Project - select Cross Platform -select Blank app (Xamarin.Forms.Portable).

Xamarin

Now, the Xamarin.Forms project has been created. Here, you can see different projects as Portable Portable Project, which contain views, ViewModels and Models.

Droid Android Project is used to run the solution on an Android platform.

  • iOS
    iOS Project is used to run the solution on iOS platform.

Now create an app, repositories, and service folders. Move all three projects to App folder.

Step 2

Now, in this project, we are going to use MVVM library, so go to portable project, select to Add Nuget Packages, Add MvvmLightLibs

Select Blank App (Xamarin.Forms.Portable)

Step 3

Create some folders in Portable project named Views, ViewModels, Models, Helpers, and Converters. 



Folder Details are given below.

  • Views
    Consists all the View files (UI) like XAML.

  • ViewModels
    Consists all the ViewModels.

  • Models
    Consists of all Models.

  • Helpers
    Consists of Helpers like Network Connectivity etc.

  • Converters
    Consists of Converters such as Image Converter etc.

Step 4

Now, go to Repositories folder and add New Project. Select Class Library (Xamarin.Forms), add new class library named My Sample App. IRepositories (Portable).

Select Blank App (Xamarin.Forms.Portable)

MySampleApp.IRepositories project will contain all the interfaces of the repositories.

Step 5

Now, go to Repositories folder and add New Project, select Class Library (Xamarin.Forms), add new class library named MySampleApp.Repositories (Portable).

Select Blank App (Xamarin.Forms.Portable)

MySampleApp.Repositories project will contain all the repositories which implement IRepositories.

Step 6

Now, go to Services folder and add New Project, select Class Library (Xamarin.Forms), add new class library named MySampleApp.Services (Portable).

Select Blank App (Xamarin.Forms.Portable)

MySampleApp.Services (Portable) project contains all the Services like SQLite tables, Models, Table Operations etc.

Now, the solution is ready to use.

Up Next
    Ebook Download
    View all
    Learn
    View all