XAML Field Modifiers in Xamarin.Forms

The x:FieldModifier namespace attribute specifies the access level for generated fields for named XAML elements.

Overview

Valid values of the attribute are:

  • Public – specifies that the generated field for the XAML element is public.
  • NotPublic – specifies that the generated field for the XAML element is internal to the assembly.

If the value of the attribute isn't set, the generated field for the element will be private.

The following conditions must be met for an x:FieldModifier attribute to be processed:

  • The top-level XAML element must be a valid x:Class.
  • The current XAML element has an x:Name specified.

The following XAML shows examples of setting the attribute:

<Label x:Name="privateLabel" />
<Label x:Name="internalLabel" x:FieldModifier="NotPublic" />
<Label x:Name="publicLabel" x:FieldModifier="Public" />

Note

The x:FieldModifier attribute cannot be used to specify the access level of a XAML class.