Xamarin, a platform for building Android and iOS apps with .NET and C#. It is Free, it is cross platform and it is open source; so let’s get started at the very basic, a good old-fashioned Hello World.
Setup
The first thing you need to do is to set up your development environment, start by downloading Visual Studio 2019 if you don’t have it already and make sure to select Mobile development with .NET workload during installation.
If you’re already a .NET developer it is very likely that you already have installed Visual Studio, if this is your case and you haven’t included this workload over the initial installation you can add it by opening the Visual Studio Installer. Select your Visual Studio 2019 installation and select More > Modify; check the Mobile development with .NET and click Modify.
Create app
Ok, now we are ready to create our app! As simple as following the next steps.
- Open Visual Studio 2019.
- Select Create a new project.
- Select Mobile from the Project type drop-down.
- Select the Mobile App (Xamarin.Forms) template and click Next.
- Enter HelloXamarin (or whatever name you’d like) and click Create.
- Select the Blank template. Ensure Android and iOS are both selected, and click OK.
Visual Studio will prompt you to install the Android SDK if it is not already installed.
Run
Once Visual Studio finishes downloading required SDKs and restoring NuGet packages let’s run our app.
Click Run on Android Emulator. Since it is the first time, you will be prompted to create a new device; you can just click Create and go with the default settings or customize it your way.
Once VS is finished downloading device image you should be able to start your emulator, wait a few seconds for it to start and click Run again.
It’s alive! Now let’s go for that promised Hello World.
Hello World
Another cool feature about Xamarin is XAML Hot Reload, this means you can make changes to your XAML files while the application is running and the UI will update automatically.
So let’s open MainPage.xaml from the Solution Explorer and let’s replace the text Welcome to Xamarin.Forms! with our Hello World! and remove the unnecessary code.
Save the file and magic! That’s it, we have our Xamarin Hello World app running in our emulator.