The XAML language namespace is the part of XAML that belongs to the language and not to a framework: the names that every XAML reader gives the same meaning. It is declared as http://schemas.microsoft.com/winfx/2006/xaml and written with the prefix x; .NET MAUI files also use http://schemas.microsoft.com/winfx/2009/xaml for it. A name in it is either a directive, used as an attribute or property element on any object, or a type, used as an element or as a markup extension. The reader that implements it in .NET is the System.Xaml library; WPF, Workflow Foundation and the other frameworks add to it.
2006 and 2009
There are two specifications, MS-XAML (2006) and MS-XAML-2009. Both give http://schemas.microsoft.com/winfx/2006/xaml as the namespace of their x: schema. The 2006 one lists the directives x:Class, x:Subclass, x:ClassModifier, x:FieldModifier, x:Name, x:Key, x:Uid and x:TypeArguments, and the types x:Array, x:Static, x:Type, x:Null, x:Code, x:XData and the primitives. The 2009 one adds x:Arguments, x:FactoryMethod and x:Reference, and names the implicit directives x:Initialization and x:PositionalParameters where the 2006 one has x:InitializationText and x:ConstructorArgs.
The .NET documentation uses “XAML 2009” for the changes of the second one: x:Arguments, x:FactoryMethod, x:Reference, built-in primitive types such as x:Char, x:Key as an element, xmlns on property elements, and event attributes that are wired when the XAML is loaded. WPF accepts the 2009 features only in XAML that is not markup-compiled, not in markup-compiled XAML or BAML. The .NET MAUI documentation writes http://schemas.microsoft.com/winfx/2009/xaml for its x:; the WPF, UWP and Avalonia documentation write the 2006 URI. Which URI Workflow Foundation and Xamarin.Forms files use was not checked, and neither the WPF documentation nor the System.Xaml source mentions the 2009 URI. The viewer accepts either URI as the language namespace.
Directives
| Name | Used on | Meaning and rules | Where |
|---|---|---|---|
x:Class | the root | the CLR class that the markup and the code-behind make together, Namespace.Class with no assembly and no nested class; only the last dot separates the namespace. Valid only on the root; the root’s element type is the base class | WPF, UWP, WinUI, MAUI, Avalonia, WF (the class of a custom activity) |
x:ClassModifier | the root, with x:Class | the access level of the generated class: public (default) or internal in C#, Public or Friend in Visual Basic. The root of a WPF page; in .NET MAUI the values are Public, Internal and NotPublic | WPF, MAUI |
x:Subclass | the root, with x:Class | the name of a derived class, for languages that have no partial classes; the x:Class is then the base | WPF |
x:FieldModifier | an object with x:Name | the access level of the field the compiler makes for the name: default private (NotPublic); public in C#, Public in Visual Basic. The root must have an x:Class. In .NET MAUI the values are Private, Public, Protected, Internal and NotPublic | WPF, UWP, WinUI, MAUI |
x:Name | any object | a name, unique in its name scope; it matches the grammar XamlName (below); the compiler makes a field of that name. Frameworks map their own Name property to it (FrameworkElement.Name), so Name="a" and x:Name="a" are the same, and giving both with different values is an error | all |
x:Key | an item of a dictionary | the key the item is stored under: a string, or in WPF a markup extension ({x:Type local:A}, a ComponentResourceKey). XAML 2009 allows <x:Key> as a property element holding an object. Needed by every item of a ResourceDictionary except a Style with a TargetType and a DataTemplate with a DataType (UWP and WinUI also accept an x:Name as the key) | all |
x:Shared | an item of a dictionary | true (default): one instance for every lookup; false: a new instance for each use (for resources that cannot be shared, such as an element) | WPF, Avalonia |
x:Uid | any object | an identifier used to localise the object; WPF’s globalisation tools use it, and WPF does not enforce that it is unique. UWP and WinUI map x:Uid="Save" to the resource names Save.Content, Save.Text and so on in .resw files | WPF, UWP, WinUI |
x:TypeArguments | a generic type’s element | the type arguments, comma separated, with prefixes: x:TypeArguments="sys:String, sys:Int32"; on the root with x:Class it makes a generic base class (PageFunction) | WPF (in XAML 2006 only on the root with x:Class, such as a PageFunction; elsewhere in loose XAML), MAUI, Avalonia |
x:Arguments | an object | a property element whose children are the arguments of the constructor, or of the factory method; it comes before any other content of the object | XAML 2009: MAUI, Avalonia; WPF in loose XAML |
x:FactoryMethod | an object | the name of a static method that makes the object, with x:Arguments for its arguments | XAML 2009: MAUI; WPF in loose XAML |
x:Code | a direct child of the root, which has an x:Class | a block of code in the language of the page, usually in a CDATA section; in WPF it must be compiled, and it becomes members of the partial class of the page | WPF |
x:Members, x:Member, x:Property | the root with x:Class | declare members on the class the markup defines: <x:Members><x:Property Name="Message" Type="propertyType"/></x:Members>. System.Xaml defines them and leaves their meaning to the framework; the format of the type is framework specific | Windows Workflow Foundation |
x:ClassAttributes | — | defined by System.Xaml as a list of attributes for the class; what a framework does with it is not described here | System.Xaml |
x:ConnectionId | — | defined by System.Xaml, with an integer value; what a markup compiler does with it is not described here. It is not written by hand | System.Xaml |
x:SynchronousMode, x:AsyncRecords | — | defined by System.Xaml (AsyncRecords takes an integer); the values of SynchronousMode and the use of both are not described here | System.Xaml |
x:DataType | a template, or any element | the type that compiled bindings below it bind to; the language-level name of DataType in the compiled-binding frameworks | UWP, WinUI, MAUI, Avalonia |
x:Load, x:DeferLoadStrategy | an element | create the element only when asked for (x:Load="False" is realised later by FindName or a binding to x:Load); x:DeferLoadStrategy="Lazy" is the earlier form | UWP, WinUI |
x:Phase, x:DefaultBindMode | an element | the phase in which a compiled binding in a recycled item updates; the default mode of x:Bind below the element | UWP, WinUI |
x:CompileBindings | the root or any element | True or False: compile {Binding} to code below this element (Avalonia) | Avalonia |
xml:space, xml:lang, xml:base | any element | white space handling (file structure), the language of a text (WPF’s FrameworkElement.Language), and the base address; the XML names, in the XML namespace and not in the x namespace. System.Xaml defines all three | System.Xaml |
The language also defines implicit directives that are never written: x:Initialization (the text that initialises an object), x:Items (the items of a collection), x:PositionalParameters (the positional arguments of a markup extension) and x:UnknownContent (content a type cannot hold). They show up in the node streams of System.Xaml, not in files; System.Xaml spells them with a leading underscore (_Items), and the 2006 specification calls the first and third x:InitializationText and x:ConstructorArgs.
Types and markup extensions
| Name | Forms | Meaning |
|---|---|---|
x:Null | {x:Null} or <x:Null/> | null; the only way to set a property to null in markup |
x:Type | {x:Type local:Person} or <x:Type TypeName="local:Person"/> | a System.Type; also the type-valued form of TargetType and DataType (TargetType="Button" is the same as TargetType="{x:Type Button}" in WPF). XAML 2009 adds a syntax for generic types; the .NET MAUI documentation puts nested type arguments in parentheses. In .NET MAUI, x:Type is a markup extension of the XAML 2009 set |
x:Static | {x:Static Class.Member} or <x:Static Member="Class.Member"/> | the value of a static field, static property, constant or enumeration member; written Type.Member with a prefix when the type is in another namespace ({x:Static sys:Int32.MaxValue}, {x:Static SystemColors.ControlBrushKey}) |
x:Array | <x:Array Type="sys:String"><sys:String>a</sys:String>…</x:Array> | a .NET array; the Type is required and names the element type; used where the framework’s own collections are not wanted. The documentation shows it in the element form; in XAML 2009 it is a language primitive and not a markup extension |
x:Reference | {x:Reference elementName} | a reference to a named object (x:Name) in the same document; Name is its content property. It is a XAML 2009 construct: WPF accepts it only in XAML that is not markup-compiled, where ElementName in a binding is still the usual way. .NET MAUI uses it with data bindings |
x:XData | <x:XData>…any XML…</x:XData> | a block of arbitrary XML kept as data, for XmlDataProvider: its content is not read as XAML; the root of the data usually has xmlns="" |
x:Code | <x:Code><![CDATA[ … ]]></x:Code> | see above |
x:Member | <x:Member Name="…"/> | declares a member inside x:Members (see above) |
x:Bind | {x:Bind …} | a compiled binding (UWP, WinUI); see data binding |
x:True, x:False | {x:True}, {x:False} | the boolean values; compiler intrinsics of Avalonia, useful where the target is an object and the text True would stay a string |
XAML 2009 primitive types
XAML 2009 gives common .NET types names in the language namespace so that a file does not need a mapping for the core library:
| Name | Type | Name | Type |
|---|---|---|---|
x:Boolean | System.Boolean | x:Int64 | System.Int64 |
x:Byte | System.Byte | x:Object | System.Object |
x:Char | System.Char | x:Single | System.Single |
x:Decimal | System.Decimal | x:String | System.String |
x:Double | System.Double | x:TimeSpan | System.TimeSpan |
x:Int16 | System.Int16 | x:Uri | System.Uri |
x:Int32 | System.Int32 |
In a file that declares the 2006 namespace, the same types come from a mapping (xmlns:sys="clr-namespace:System;assembly=mscorlib" and <sys:String x:Key="a">); UWP and WinUI provide x:String, x:Int32, x:Double and x:Boolean, and Avalonia provides x:String, x:Int32, x:Double and x:Boolean, in their 2006 namespace too. The .NET MAUI documentation also lists x:DateTime, which is not in the table. The MS-XAML 2006 specification already lists the primitives; the .NET documentation calls them XAML 2009 additions.
The XamlName grammar
The value of x:Name and the names of types and members must follow this grammar of the XAML specification:
XamlName ::= NameStartChar ( NameChar )*
NameStartChar ::= LetterCharacter | '_'
NameChar ::= NameStartChar | DecimalDigit | CombiningCharacter
LetterCharacter ::= UnicodeLu | UnicodeLl | UnicodeLo | UnicodeLt | UnicodeNl
DecimalDigit ::= UnicodeNd
CombiningCharacter::= UnicodeMn | UnicodeMc
DottedXamlName ::= XamlName '.' XamlName
So myName, _x2 and a name in any script that has letters are valid, and 2nd, my-name and my name are not. A DottedXamlName names a property or event of a type (Grid.Row), including an attached one. The compiler also needs the name to be a valid identifier of the code-behind language, which is a little narrower in practice.
Not described
Known, not yet covered
- Reference: the table states the frameworks where the documentation says the name works; whether a name is accepted by a version of a framework that the documentation does not mention was not tested.
- Reference: the full property list of
x:XDataand the exact value sets ofx:FieldModifierandx:ClassModifierin each language (they depend on the compiler’s CodeDom provider) are not given. - Viewer: the viewer warns about an
x:name it does not know, and takes the names above as the known set; a framework that adds its ownx:name would be warned about. - Reference: the rows for Avalonia, UWP, WinUI and .NET MAUI come from each framework’s documentation and the Avalonia compiler source; Xamarin.Forms and Silverlight were not read.
Unknown
- Reference: the vocabulary specifications MS-XAMLV (and the WPF and Silverlight vocabulary specifications) could not be opened: the address the site was written against returns not found. MS-XAML and MS-XAML-2009 were read.
- Reference: which URI Workflow Foundation and Xamarin.Forms files use for
x:, and what a markup compiler does withx:ConnectionId,x:SynchronousMode,x:AsyncRecordsandx:ClassAttributes.