.NET, Xamarin, and mobile software development

A BLOG BY DAN HERMES

Cross-platform UI Coup: Xamarin.Forms

18 June 2014No Comment

One of the biggest problems with C# mobile development, platform-specific UI, is solved with Xamarin 3.

The greatest foe we face in our quest for cross-platform implementation is platform-specific code. Code that is platform-specific must be implemented differently depending on the platform, whether iOS , Android, or Windows Phone. Cross-platform patterns are the same regardless of operating system. Cross-platform code is sometimes referred to as shared code, or core code, as it is shared between projects for different mobile operating systems. Certain types of code lend themselves well to cross-platform sharing and other code less so. The rule of thumb is that the closer the code is to the user, the harder it is to share. The most reusable code is the server-side web service. The client-side data layer is often reusable. The business logic tends to be partially entwined with the UI so there is overlap here between platform-specific and cross-platform code. UI code is nearly impossible to share between platforms. Nearly impossible until the release of Xamarin 3 which includes Xamarin.Forms.

As of Xamarin 3, cross-platform UI can be developed using Xamarin.Forms, built with XAML markup or coded in C# using Page, Layout, and Control classes. This API provides a broad range of built-in cross-platform mobile UI patterns. Beginning with the highest-level Page objects it provides familiar layers of Navigation and Tabbed menus then Content, MasterDetail, and Carousel for the main form. Layouts span all the standard formats we use on all platforms including Stack, Absolute, Relative, Grid, ContentView, ScrollView, and Frame. Used within those are dozens of familiar controls such as ListView, Button, DatePicker, and TableView. Many of these have data-binding options using an MVVM approach.