Xamarin Forms Ch1-project Architecture

Source: Internet
Author: User

Before we start any project, the structure of project contents including folder name, third party package referencing need To is settled properly. In this very first sections of Xamarin Tutorial, the detailed planning of Xamarin Form project is illurstrated and Explaine D.

1. Project Architecture

A typical Xamarin Form project consists of many sections, such as a PCL project that contains business logic, UI (either I n Code or XAML), Data Access, Web service connection etc, an Android project which has Android platform specific settings, Configurations and resources, an IOS project. In addition, Unit testing and UI automated testing projects is included as well to improve quality of the code.

2. Folder Structure

Folder, in general, was a useful tool to group related information, and present it with meaningful name. In software project, with a well defined folder, the project was more concise and possibly can improve the maintainability. As majority code is sitting in the PCL project, we'll pay more attention in the Samplearchitecture project.

Before I explain the detailed folders, I want to make sure everyone is understanding the pattern of MVVM. The pattern is actually derived from MVC pattern, which enforces the separation of user inferface design to make the code is more testable and clear.

2.1 Model

Model refers the domain design. In object oriented approach, it represents objects in the real world, such as Teacher, Student. And all of the objects would be placed within Model folder, under Samplearchitecture.model namespace.

2.2 View

View is user interface of the project. In Xamarin form, there is the ways of writing UI, either completely in Code or Write Xaml. In the project, I choose Xaml as the syntax are more concise and are well known if the developer have WPF or Silverlight back  Ground. So, all mobile pages would be places within view folder, and it can is further divided into subfolder such as registration, Schoolmanagement etc according to project features.

2.3 ViewModel

ViewModel is the bridge between Model and View. It encapsulates the logic data from Model and presents it in the View based on the needs. Hence, most of logic and processing code should all is placed within ViewModel.

2.4 Controls

Controls folder, is where we put customized controls. Xamarin form is still a relative new platform, there was controls need to being customized in order to meet specific project Requirements. For example, Underlineentry are a control that extends class Entry, and providing one single line below the input box.

2.5 Helpers

Helpers folder, is the place for utility class which provides functions can be used across the application, such as Appcon Stant.cs-constant value for project, Settings.cs-project Settings. In general, those class is static.

2.6 Network

Network folder, is where we handle network connection.

2.7 Service

Service folder, contains abstract and concrete subfolders. And this are the place we set up the interface of data request and fetching data through Web service, then pass the data to The ViewModels.

3. Package Architecture


Here are the list of packages that I referenced in this sample project. And the detailed use of those packages would be a explained in the following section.

3.1 AUTOFAC

Autofac is a popular dependency injection tool. Please be refer to the documentation is your not familiar with it.

3.2 Xamarin Forms Labs

Xlabs is an open source project, aims to provide a powerful and cross platform set of services and controls tailored T o Work with Xamain Forms.

3.3 Propertychanged.fody

The add-in injects inotifypropertychanged code into properties.

3.4 Microsoft.Net.Http

This package includes HttpClient for sending requests over HTTP, as well as httprequestmessage and httpresponsemessage for Processing Http Messages.

So far, I went through the first step of starting a typical Xamarin Form project. In the next secion, I'll show you how to configure those packages and compile the project successfully.

Xamarin Forms Ch1-project Architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.