Xamarin Forms: one code to rule them all

Also available in portuguese

“I am a C# developer and I want to create a mobile app for all platforms but I don’t program in Objective-C or Java and I don’t want to spend time and money with that. How Xamarin Forms could help me?”

There a lot of mobile devices for three platforms:
– Android. 90% of devices, Java programming language.
– iOS. 9% of devices, Objective-C programming language. You will need a MAC.
– Windows Phone. 1% of devices, C# programming language.

OK, Xamarin is a C# framework to create mobile app for iOS and android using C# language. OK ok ok, you can create mobile app for windows phone too.

You can use Xamarin.iOS  to create mobile user interface for iOS and use Xamarin.Droid to create mobile user interface for Android.

You just need to install Xamarin plugin for Visual Studio on Windows or use Xamarin Studio IDE on Mac.

Using Xamarin.Droid or Xamarin.iOS for mobile user interface you will need to write two codes: one for android and another one for iOS. There are some small parts of code you can share between those projects like database access and business logic.

They call that of traditional Xamarin aproach:

Xamarin Forms: one code to rule them all

“Oh gosh! Write two mobile user interfaces?? Is there a another or a better way?”

Yes! Xamarin Forms!

You can use Xamarin.Forms to write only one code and run your app in iOS and Android. Xamarin Forms is an abstraction that works together with Xamarin.iOS and Xamarin.Droid. If you create a mobile user interface in Xamarin Forms you don’t need to create the same user interface on Xamarin.Droid or Xamarin.iOS. The mobile user interface is shared between them.

They call that of Xamarin Forms aproach:

Xamarin Forms: one code to rule them all

“I don’t believe, it’s magic, just one code to rule them all!”

Alright, take it easy. Is not that simple. Xamarin Forms helps a lot, but some things you will still need an adjustment only for iOS or Droid projects. But, yes, a lot of code are shared between those projects and helps a lot.

Anyway, in my opinion it’s still better using Xamarin Forms than learn Java or Objective-C and write two distinct mobile app.  With Xamarin Forms you share backend methods, classes and off course the user interface.

“So, how Xamarin Forms works?”

When you create a Xamarin Forms project (Cross-mobile) using Visual Studio, it creates a solution file with three Xamarin projects:

1 – Portable project (Xamarin Forms)
2 – Android project (Xamarin.Droid)
3 – iOS project (Xamarin.iOS)

Solution structure:

Xamarin Forms: one code to rule them all

Just for understanding, imagine Xamarin.Forms like a reusable DLL and Xamarin.iOS and Xamarin.Droid projects like web projects that references that reusable DLL. In web programming, you deploy the web project and for Xamarin it’s the same, you deploy Xamarin.Droid and Xamarin.iOS for respective devices.

If you want you can install and configure Xamarin in your Visual Studio 2015 or download a demo project like Button Border and Radius in Xamarin Forms.

This is it. I hope it helped.

Xamarin Forms: one code to rule them all

Xamarin Forms: Questions, suggestions and feedbacks will be appreciated. Good luck!

About the Author:
He works as a solution architect and developer, has more than 16 years of experience in software development on several platforms and more than 14 years only for the insurance market.