XAML Compilation

Using the XAML compiler to increase the performance of a Xamarin.Forms app

PDF for offline use
Related APIs:

Let us know how you feel about this

Translation Quality


last updated: 2016-01

XAML can be optionally compiled directly into intermediate language (IL) with the XAML compiler (XAMLC).

XAMLC offers a number of a benefits:

  • It performs compile-time checking of XAML, notifying the user of any errors.
  • It removes some of the load and instantiation time for XAML elements.
  • It helps to reduce the file size of the final assembly by no longer including .xaml files.

XAMLC is disabled by default to ensure backwards compatibility. It can be enabled at both the assembly and class level by adding the XamlCompilation attribute.

The following code example demonstrates enabling XAMLC at the assembly level:

using Xamarin.Forms.Xaml;
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace PhotoApp

In this example, compile-time checking of all the XAML contained within the PhotoApp namespace will be performed, with XAML errors being reported at compile-time rather than run-time. The assembly prefix to the XamlCompilation attribute specifies that the attribute applies to the entire assembly.

The following code example demonstrates enabling XAMLC at the class level:

using Xamarin.Forms.Xaml;
[XamlCompilation (XamlCompilationOptions.Compile)]
public class HomePage : ContentPage

In this example, compile-time checking of the XAML for the HomePage class will be performed and errors reported as part of the compilation process.


Note: The XamlCompilation attribute and the XamlCompilationOptions enumeration reside in the Xamarin.Forms.Xaml0 namespace, which must be imported to use them.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.