Create a Xamarin.Forms app

Overview

This tutorial shows you how to add a cloud-based backend service to a Xamarin.Forms mobile app using an Azure Mobile App backend. You will create both a new Mobile App backend and a simple Todo list Xamarin.Forms app that stores app data in Azure.

Completing this tutorial is a prerequisite for all other Mobile Apps tutorials for Xamarin.Forms.

Prerequisites

To complete this tutorial, you need the following:

Note

If you want to get started with Azure App Service before signing up for an Azure account, go to Try App Service, where you can immediately create a short-lived starter Mobile App in App Service. No credit cards required; no commitments.

Create a new Azure Mobile App backend

Follow these steps to create a new Mobile App backend.

  1. Log in at the Azure Portal.
  2. Click +NEW and type Mobile Apps in Search the marketplace. Select Mobile Apps Quickstart and click Create.

    Azure Portal with Mobile Apps Quickstart highlighted

  3. For the Resource Group, select an existing resource group, or create a new one (using the same name as your app.)
  4. Click Create. Wait a few minutes for the service to be deployed successfully before proceeding.

You have now provisioned an Azure Mobile App backend that can be used by your mobile client applications. Next, you will download a server project for a simple "todo list" backend and publish it to Azure.

Configure the server project

Follow the steps below to configure the server project to use either the Node.js or .NET backend.

  1. Click App Services > select your Mobile App backend > click Quickstart > your client platform (iOS, Android, Xamarin, Cordova).

Azure Portal with Mobile Apps Quickstart highlighted

  1. If the connection to the database is not configured, you must create one Data Connection.

Azure Portal with Mobile Apps Connect to BD

  • Create new SQL Database and server.

    Azure Portal with Mobile Apps create new BD and server

  • Wait until the data connection is successfully created.

    Azure Portal with Mobile Apps notification on data connection create

  • Data connection must be successful.

    Azure Portal with Mobile Apps notification on data connection create

  1. Under 2. Create a table API, select Node.js for Backend language. Accept the acknowledgment and click Create TodoItem table. This creates a new TodoItem table in your database. Remember that switching an existing backend to Node.js will overwrite all contents! To create a .NET backend instead, follow these instructions.

Download and run the Xamarin.Forms solution

Here you have a couple of choices. You can download the solution to a Mac and open it in Xamarin Studio, or you can download the solution to a Windows computer and open it in Visual Studio using a networked Mac for building the iOS app. See Setup and install for Visual Studio and Xamarin if you need more detailed instructions on the Xamarin setup scenarios.

Let's proceed:

  1. On your Mac or on your Windows computer, open the Azure Portal in a browser window.
  2. On the settings blade for your Mobile App, click Get Started (under Mobile) > Xamarin.Forms. Under step 3, click Create a new app if it's not already selected. Next click the Download button.

    This downloads a project that contains a client application that is connected to your mobile app. Save the compressed project file to your local computer, and make a note of where you save it.

  3. Extract the project that you downloaded, and then open it in Xamarin Studio or Visual Studio.

(Optional) Run the iOS project

This section is for running the Xamarin iOS project for iOS devices. You can skip this section if you are not working with iOS devices.

In Xamarin Studio

  1. Right-click the iOS project, and then click Set As Startup Project.
  2. On the Run menu, click Start Debugging to build the project and start the app in the iPhone emulator.

In Visual Studio

  1. Right-click the iOS project, and then click Set as StartUp Project.
  2. On the Build menu, click Configuration Manager.
  3. In the Configuration Manager dialog box, select the Build and Deploy checkboxes of the iOS project.
  4. Press the F5 key to build the project and start the app in the iPhone emulator.

    Note

    If you have problems building, run NuGet package manager and update to the latest version of the Xamarin support packages. Sometimes the Quickstart projects may lag behind in being updated to the latest.

In the app, type meaningful text, such as Learn Xamarin and then click the + button.

This sends a POST request to the new mobile app backend hosted in Azure. Data from the request is inserted into the TodoItem table. Items stored in the table are returned by the mobile app backend, and the data is displayed in the list.

Note

You'll find the code that accesses your mobile app backend in the TodoItemManager.cs C# file of the portable class library project of your solution.

(Optional) Run the Android project

This section is for running the Xamarin droid project for Android. You can skip this section if you are not working with Android devices.

In Xamarin Studio

  1. Right-click the Android project, and then click Set As Startup Project.
  2. On the Run menu, click Start Debugging to build the project and start the app in an Android emulator.

In Visual Studio

  1. Right-click the Android (Droid) project, and then click Set as StartUp Project.
  2. On the Build menu, click Configuration Manager.
  3. In the Configuration Manager dialog box, select the Build and Deploy checkboxes of the Android project.
  4. Press the F5 key to build the project and start the app in an Android emulator.

    Note

    If you have problems building, run NuGet package manager and update to the latest version of the Xamarin support packages. Sometimes the Quickstart projects may lag behind in being updated to the latest.

In the app, type meaningful text, such as Learn Xamarin and then click the + button.

This sends a POST request to the new mobile app backend hosted in Azure. Data from the request is inserted into the TodoItem table. Items stored in the table are returned by the mobile app backend, and the data is displayed in the list.

Note

You'll find the code that accesses your mobile app backend in the TodoItemManager.cs C# file of the portable class library project of your solution.

(Optional) Run the Windows project

This section is for running the Xamarin WinApp project for Windows devices. You can skip this section if you are not working with Windows devices.

In Visual Studio

  1. Right-click any of the Windows projects, and then click Set as StartUp Project.
  2. On the Build menu, click Configuration Manager.
  3. In the Configuration Manager dialog box, select the Build and Deploy checkboxes of the Windows project that you chose.
  4. Press the F5 key to build the project and start the app in a Windows emulator.

    Note

    If you have problems building, run NuGet package manager and update to the latest version of the Xamarin support packages. Sometimes the Quickstart projects may lag behind in being updated to the latest.

In the app, type meaningful text, such as Learn Xamarin and then click the + button.

This sends a POST request to the new mobile app backend hosted in Azure. Data from the request is inserted into the TodoItem table. Items stored in the table are returned by the mobile app backend, and the data is displayed in the list.

Note

You'll find the code that accesses your mobile app backend in the TodoItemManager.cs C# file of the portable class library project of your solution.

Next steps