Compiled rather than interpreted

Introduced in Xamarin Forms 2.0, compiled XAML or XAMLC allows for your UI markup to be compiled rather than interpreted (at runtime).

There are couple of benefits to this approach.  Firstly, the .XAML files will no longer be bundled with your app, they will be compiled into it, reducing the size of the app.

Second, you’ll get notified of errors at compile time rather than runtime – helping your development workflow keep moving along.

Third, without the overhead of interpreting, your load times for XAML will benefit.

Enabling XAMLC

XAML compliation can be enabled at either assembly or class level, simply by adding the XamlCompilation attribute.

Class Level

To enable compilation for an individual class, add the XamlCompilation attribute, with the value XamlCompilationOptions.Compile:

    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();

Assembly Level

Alternatively, add the attribute to a namespace and add the assembly prefix to apply it to an entire assembly:


[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace App1
{
public partial class App : Application

Wrap-up

XAML compilation is an easy way to improve performance in your Xamarin Forms app, and give yourself a little compile time checking too.