Creating New Project In Xamarin

This blog is about creating a new blank project in Xamarin and also about creating your first cross platform app.

Introduction

In this article, you will learn how to create a new Xamarin cross-platform project. And also, you'll learn how to run it on different platforms. Follow these steps to build a cross-platform app.

  1. If you have Xamarin successfully installed, just open “Visual Studio” and click on “File” on the top left corner and go through “New” to click on “Project”.

    Creating New Project In Xamarin

  2. After you click, a new window will open. Click “Cross-Platform” if you want to build a cross-platform application. You can also select Android or iOS for the platform specific application. Now, choose “Mobile App (Xamarin Forms)” and name the project as you like; then click “OK”.

    Creating New Project In Xamarin

  3. There are multiple types of pages in Xamarin about which you will learn in my upcoming articles. You can make “Master Detail”, “Tabbed” or many other types of pages. But for now, as a beginner, simply select “Blank” and click “OK”. The project will start to create. It will take some time whenever you create a new project.

    Creating New Project In Xamarin

  4. After the project is created, you can run project specific to your OS and device. Select “UWP” for Windows and “Local Machine” on the top of the bar. For “Android”, you should have a smartphone or an emulator installed on your PC. Visual Studio 2017 provides some built-in emulators for Android so you don’t need to worry about them. So, in that case, select Android and an emulator on which you want to test the project. If you have an Android device connected with your PC, simply select that device. In the case of iOS, you should have an Apple device.

    The first time the page consists of a ContentPage and a Label with a Text “Welcome to Xamarin.Forms!”

    Creating New Project In Xamarin

  5. It will take some time the first time you run the project so just keep calm. To reduce the time, you can simply go to “Build” in the menu bar and open “Configuration Manager” and select your Platform to build a project on. Unmark unnecessary options to save time. For now, I am going to select “UWP”.

    Creating New Project In Xamarin

  6. After that, click the Play button naming “Local Machine” and run the project. As I told you before, it will take some time the first time you run it. And this will be your first output.

    Creating New Project In Xamarin

XAML Code

  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:PracApp1" x:Class="PracApp1.MainPage">  
  3.     <StackLayout VerticalOptions="Center" HorizontalOptions="Center">  
  4.         <Label Text="Welcome To Xamarin Forms!"></Label>  
  5.     </StackLayout>  
  6. </ContentPage>  
C# Code

  1. using PracApp1.Models;  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.Collections.ObjectModel;  
  5. using System.Linq;  
  6. using System.Text;  
  7. using System.Threading.Tasks;  
  8. using Xamarin.Forms;  
  9. namespace PracApp1 {  
  10.     publicpartialclassMainPage: ContentPage {  
  11.         public MainPage() {  
  12.             InitializeComponent();  
  13.         }  
  14.     }  
  15. }  

Creating applications with Xamarin is much easier compared to other languages because it allows you to build a cross-platform application. I hope reading this article allowed you to create new Xamarin project much more efficiently and provides you the knowledge about cross-platform and platform-specific applications.