Quick Start Tutorial: Creating Universal Apps Via Xamarin - Part Two

The first part of this tutorial was a quick start for info about Xamarin; this article explains about Xamarin Forms with XAML.

Xamarin.Forms Portable Project


The core functionality of this option is to share the UI. This UI is developed via XAML or C# code files. Before going into detail about Xamarin forms, first let’s create a sample application Xamarin form with XAML.

Steps

  1. Creating sample Xamarin Forms Application using XAML .

    File -> New Project -> Visual C# -> Cross-Platform -> Blank App (Xamarin. Forms Portable)



  2. Creating Xamarin project, UWP project prompt to the SDK version (VS Update 2 features)



    Project has successfully been created.

    Now add XAML Page.

    Go to Portable project -> Add new Item -> Cross – platform -> Forms XAML Page.



    Open newly created page (changed Label text).



  3. Open App.cs file in Sample 1(Portable) projec, remove the code in App () creator and create an object forthe  newly added page.



  4. Compile the project.

    Note

    Default UWP Programming is not selected in the Project build, we have to select the project (Build -> Configuration Manager), because UWP application must refer to the x86 architecture, not for any CPU option (check other projects, default it was selected as Any CPU option and iOS selected as iPhone or iPhone simulator)



  5. Select the project and run the application.

    The same output on three different platforms (Android, Universal Windows Platform, Windows Phone 8.1)

Steps into the Application

Xamarin forms application is mainly two components and both are together,

  1. App Object
  2. Page Object

Application object

App object is the same as application object in the C# programs and it holds the page object, it maintains the complete life cycle of the application.

Life cycle of the application

The Mobile application life cycle of the handling application is entirely different compared to the desktop application, in mobile application only one application is  visible to the user, in the background another application may or may not be running.

If an application is running in the background here is how to handle our application or go back to visible stage. This type of situation is based on the application needs for example: Filling in the form data in between switching from one app to another app, this time we need to store the form data, go back to our application, and display the same state where the user has left.

Xamarin supports three types of the life cycle functionality: Start, Sleep, Resume.

OnStart, Application is launching (first time), loading the required info whether app or user is required, the App is going to background mode or invisible to the user (user is opening another app). This time if you want store the app data, OnSleep method is storing the data (Note: OS is giving a small amount of time to handling this function, so store only required information), OnResume method is used to retrieve the information or restore the app state back to the user when application is visible to user.

Application holds the Page via MainPage property, starting page of the application should be assigned to this property,



Page holds the container and it holds the collection of controls, Internal diagram for Xamarin Forms

Each Item (common controls, container, Page) we will see one-by-one later 

Up Next
    Ebook Download
    View all
    Learn
    View all