Remarks

Xamarin.Forms is a cross-platform, natively-backed UI toolkit abstraction that allows developers to create user interfaces that can be shared across Android, iOS, and Windows Phone. Because the user interfaces use the native controls of the target platforms, they have the appearance and, importantly, the responsiveness of natively built apps.

Xamarin.Forms Solution Architecture

Cross-Platform Project

The user-experience of a Xamarin.Forms application is usually defined in a cross-platform shared project (either a Portable Class Library or a Shared Project) and combined with platform-specific projects that, at the least, initialize the native platform rendering (note the call to Forms.Init() in the platform code samples below) and, more generally, extend the user-experience and user-interface in platform-specific manners (for instance, by accessing platform-specific sensors or capabilities).

For example, the developer can create a cross-platform Xamarin.Forms Label and display it with the following code in the shared project:

While more complicated layouts with more useful user interfaces are more typical, this example is useful for clearly illustrating the shared and platform-specific code that Xamarin.Forms uses to create and display the code on the target platforms. The code in the following discussion is created by Visual Studio in the target platform projects when the developer creates a new Xamarin.Forms project. In each case, a platform-specific Forms.Init() method is called to intitialize forms before any other method that depends on Xamarin.Forms is called.

iOS Platform Code

On the iOS platform, Visual Studio registers a subclass of the framework class Xamarin.Forms.Platform.iOS.FormsApplicationDelegate as the entry point of the application, and immediately makes a call to Xamarin.Forms.Forms.Init.

Android Platform Code

The entry point on Android is a subclass of the framework class Xamarin.Forms.Platform.Android.FormsAppCompatActivity, and its OnCreate method must configure the tab bar and toolbars and call its base method before calling Forms.Init.

UWP Code

The entry point for a Xamarin.Forms app on UWP is just the constructor for a Windows.UI.Xaml.Application in App.xaml.cs in the UWP platform project. However, the application lifecycle on UWP is such that the call to Forms.Init must take place inside the OnLaunched method, and is guarded against being run more than once. The necessary code is beyond the scope of this documentation, but the curious developer is encouraged to create a test Xamarin.Forms solution and study the code in the App.xaml.cs file for more details

Elements in Xamarin.Forms

Important types in the Xamarin.Forms namespace include Page, View, and Layout. Pages typically correspond with controller objects (Activities in the Android world, UIViewControllers in the iOS world), Views with controls or widgets, and Layouts arrange Views on other Views. These types are all derived from Element.

Model-View-ViewModel and Xamarin.Forms

Application developers use the Model-View-ViewModel (MVVM) pattern to create Xamarin.Forms apps that cleanly separate the concerns of data presentation and user interface from the concerns of data storage and manipulation. The Xamarin.Forms framework enables this by providing, among a few other related types, the BindableObject and BindableProperty classes. Objects that inherit from BindableObject can be bound to members of type BindableProperty on other objects.