Prerequisites

Xamarin Studio and Visual Studio

Xamarin.Forms

Xamarin.Forms is a cross-platform UI toolkit, which allows us to efficiently create native user interface layouts, which can be shared across iOS, Android, Windows Phone, Windows Store and Universal Windows Platform apps.

Xamarin.Forms supports five distinct Application platforms.

There are four main control groups, which are used to create the user interface of Xamarin.Forms Application, which are.

Xamarin.Forms is best for.

Now, let's get started with the steps, given below.

Create a Project

Open Visual Studio 2015 and click File -> New -> Project Option for New Xamarin.Forms app.



Giving the Project Name

New Project Window will open. You can select an Installed -> Template -> C# -> Cross-Platform Cordova apps -> Blank App (Xamarin.Forms Portable).

Type the project name XamarinForms and click OK button.



Afterwards, we create the project. Our solution should resemble the following.



This is the app class. In XamarinForms project, this code is responsible to draw the text, which we had seen on the screen. In a project created by Visual Studio, the App class is defined in the App.cs file.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Xamarin.Forms;
  6. namespace XamarinForms
  7. {
  8. public class App: Application {
  9. public App() {
  10. // The root page of your application
  11. MainPage = new ContentPage {
  12. Content = new StackLayout {
  13. VerticalOptions = LayoutOptions.Center,
  14. Children = {
  15. new Label {
  16. HorizontalTextAlignment = TextAlignment.Center,
  17. Text = "Welcome to Xamarin Forms!"
  18. }
  19. }
  20. }
  21. };
  22. }
  23. protected override void OnStart() {
  24. // Handle when your app starts
  25. }
  26. protected override void OnSleep() {
  27. // Handle when your app sleeps
  28. }
  29. protected override void OnResume() {
  30. // Handle when your app resumes
  31. }
  32. }
  33. }
Run the Application

Now, we are ready to run our project. Thus, click Android 4.4 API 19 to run the Application.



Output



We can also run our app in Android, iOS and Windows device emulators. To see them all, choose any platform from the platform list on the Standard toolbar.



Conclusion

I hope you understood how to create Xamarin.Forms app, using Visual Studio and run it.