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 (XAML 2006) or http://schemas.microsoft.com/winfx/2009/xaml (XAML 2009) and written with the prefix x. 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, WF and the other frameworks add to it.
2006 and 2009
XAML 2006 is the language of WPF’s first release and of Silverlight 2 and later; it is what a WPF project writes. XAML 2009 is the revision made for .NET Framework 4: it adds the directives that construct objects (x:Arguments, x:FactoryMethod), generic types (x:TypeArguments), a reference markup extension (x:Reference), x:Key as an element, namespace declarations on property elements, event wiring at load time, and the primitive types x:String, x:Int32 and the rest. WPF accepts the 2009 features only in loose XAML read by System.Xaml, not in markup-compiled XAML or BAML. Workflow Foundation, Xamarin.Forms and .NET MAUI use the 2009 namespace; UWP, WinUI and Avalonia use the 2006 one. A file may not declare both under one prefix, and the viewer shows the one it finds on the Overview tab.
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 | WPF, UWP, WinUI, Avalonia, WF |
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 | WPF, UWP, WinUI, MAUI, Avalonia |
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, Silverlight 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 tools (LocBaml) key the localised properties by it; 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) | XAML 2009: WF, MAUI, Xamarin.Forms, Avalonia; WPF in loose files and on PageFunction |
x:Arguments | an object | a property element whose children are the arguments of the constructor, or of the factory method | XAML 2009: WF, MAUI, Xamarin.Forms, Avalonia |
x:FactoryMethod | an object | the name of a static method that makes the object, with x:Arguments for its arguments | XAML 2009: MAUI, Xamarin.Forms, Avalonia |
x:Code | the root | a block of code in the language of the page, in a CDATA section; WF’s and WPF’s markup compilation only | WPF, WF |
x:Members, x:Member, x:Property | the root with x:Class | declare properties on the class the markup defines: <x:Members><x:Property Name="Message" Type="InArgument(x:String)"/></x:Members> | WF |
x:ClassAttributes | the root | the .NET attributes of the generated class | WF |
x:ConnectionId | — | written by the markup compiler into the generated code to number the connections between objects and handlers; not written by hand | WPF, UWP, WinUI |
x:SynchronousMode, x:AsyncRecords | the root of a loose file | Async or Sync, and a record count, for the way a page is read | WPF |
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 | WPF, WF |
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.
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}"); generic types in 2009: {x:Type Foo(x:Int32)} |
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. As a markup extension in WPF only in the element form |
x:Reference | {x:Reference elementName} | a reference to a named object (x:Name) in the same document; the target must be declared before the reference in WPF, and cycles are not allowed |
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="…"/> | a reference to a member by name |
x:Bind | {x:Bind …} | a compiled binding (UWP, WinUI); see data binding |
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">); WinUI and UWP provide x:String, x:Int32, x:Double, x:Boolean and x:Object in their 2006 namespace too.
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.
Unknown
- Reference: the MS-XAML specification pages themselves were not opened here; the rules come from Microsoft’s XAML services documentation, which cites them.