Overview of Xamarin Forms

Are you new to Xamarin Forms or just wondering how it all connects together? This is a very quick and basic overview of the components and how they fit together.

When you create a new Xamarin Forms solution you do 2 things.

  1. Create a common PCL that will contain all your views and app code. This project is available across all platforms. You could also do a Shared Project, instead of a PCL but I normally do not recommend that approach.
  2. Create each individual platform specific project. E.g. if you want an iOS and Android app, you will create an Android Mobile Project and an iOS Mobile Project from the templates available in Xamarin Studio or Visual Studio.
Diagrams

Customize Per Platform

In Forms you have the ability to override the default behavior and customize to each platform as required, while still sharing most of your code and UI. You can customize as needed using the following methods.

  1. Dependency Injection – Create platform specific code in the Platform Specific Mobile App project and then inject it for use within your PCL. Xamarin comes with a default one, however you can also use other common ones such as AutoFac.
  2. Custom Renderers – Override Xamarin Forms renderers in the Platform Specific Mobile App. Xamarin Forms has dll’s in each Mobile App that provides a default renderer that converts a control (e.g. a Label, into the platform specific version of a label such as UILabel). You can override these and do extensive customization.
  3. OnPlatform switching. In your PCL (C# and XAML) you can essentially right switches that do, if Windows Phone do this, or if iOS do this. This is handy for providing different values to UI elements such as font size, which appear differently on different platforms. A font size 18 looks different on Windows compared with iOS.

PCL (Portable Class Library) – A dll that can be targeted to different platforms, e.g. WP8 or Xamarin.iOS. When your Mobile project is compiled, it compiles this dll to the format compatible with your project.

Platform Specific Mobile App – When I say this, I mean the project that is for a specific platform, e.g. your Windows phone project, that then references your PCL, or your iOS project etc

 


XAMARIN.FORMS MONTHLY NEWSLETTER

JOIN 1,000+ SUBSCRIBERS

  1. Don't miss out on updates
  2. The latest info from this site, Xamarin and the community
  3. Unsubscribe at any time*

* We use MailChimp, with double opt-in, and instant unsubscribe

Microsoft MVP | Xamarin MVP | Xamarin Certified Developer | Exrin MVVM Framework | Xamarin Forms Developer | Melbourne, Australia

Related Posts

Leave A Comment?