XAML Keywords
The XAML language namespace (http://schemas.microsoft.com/winfx/2006/xaml) defines a handful of keywords that must be treated specially by any XAML parser. They mostly control aspects of how elements get exposed to procedural code, but several are useful independent of procedural code. You’ve already seen some of them (such as Key, Name, and Class), but Table 2.2 lists all the ones relevant for Windows Store apps. They are listed with the conventional x prefix because that is how they usually appear in XAML and in documentation.
Table 2.2. Keywords in the XAML Language Namespace, Assuming the Conventional x Namespace Prefix
Keyword |
Valid As |
Meaning |
x:Boolean |
An element. |
Represents a System.Boolean. |
x:Class |
Attribute on root element. |
Defines a namespace-qualified class for the root element that derives from the element type. |
x:Double |
An element. |
Represents a System.Double. |
x:FieldModifier |
Attribute on any nonroot element but must be used with x:Name (or equivalent). |
Defines the visibility of the field to be generated for the element (which is private by default).The value must be specified in terms of the procedural language (for example, public,private, and internal for C#). |
x:Int32 |
An element. |
Represents a System.Int32. |
x:Key |
Attribute on an element whose parent is a the parent dictionary. |
Specifies the key for the item when added to the parent dictionary |
x:Name |
Attribute on any nonroot element but must be used with x:Class on root. |
Chooses a name for the field to be generated for the element, so it can be referenced from procedural code. |
x:Null |
An element or an attribute value as a markup extension.Can also appear as x:NullExtension. |
Represents a null value. |
x:StaticResource |
An element or an attribute value as a markup extension.Can also appear as |
References a XAML resource |
x:String |
An element. |
Represents a System.String. |
x:Subclass |
Attribute on root element and must be used with x:Class. |
Specifies a subclass of the x:Class class that holds the content defined in XAML.This is needed only for languages without support for partial classes, so there's no reason to use this in a C# XAML project. |
x:TemplateBinding |
An element or an attribute value as a markup extension. |
Binds to an element's properties from within a template, as described in Chapter 16.Can also appear as x:TemplateBindingExtension. |
x:Uid |
Attribute on any element |
Marks an element with an identifier used for localization. |