title | description | ms.date | helpviewer_keywords | ms.assetid | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Built-in Types for Common XAML Language Primitives |
Learn about XAML 2009 language-level support of common language runtime (CLR) primitives. |
03/30/2017 |
|
11de2f08-5b95-4989-b5ec-5178eb968184 |
XAML 2009 introduces XAML language-level support for several data types that are frequently used primitives in the common language runtime (CLR) and in other programming languages. XAML 2009 adds support for these primitives: x:Object
, x:Boolean
, x:Char
, x:String
, x:Decimal
, x:Single
, x:Double
, x:Int16
, x:Int32
, x:Int64
, x:TimeSpan
, x:Uri
, x:Byte
, and x:Array
In XAML for previous WPF versions, you could reference the CLR language primitives by mapping the assembly and namespace that contained a CLR primitive definition class for the .NET Framework. Most of these are in the mscorlib assembly and xref:System namespace. For example, to use xref:System.Int32, you could declare the following mapping (with an example usage shown thereafter):
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Application.Resources>
<sys:Int32 x:Key="intMeaning">42</sys:Int32>
</Application.Resources>
</Application>
By convention, the language primitives for XAML and all other XAML language elements are shown, including the x:
prefix. This is how XAML language elements are typically used in real-world markup. This convention is followed in the conceptual documentation for XAML in WPF and also in the XAML specification.
For CLR backing, the x:Object
primitive corresponds to xref:System.Object.
This primitive is not typically used in application markup, but might be useful for some scenarios such as checking assignability in a XAML type system.
For CLR backing, the x:Boolean
primitive corresponds to xref:System.Boolean.
XAML parses values for x:Boolean
as case insensitive. Note that x:Bool
is not an accepted alternative. For the XAML language specification definition, see [MS-XAML] Sections 7.2.17 and 7.4.11.
For CLR backing, the x:Char
primitive corresponds to xref:System.Char.
String and char types have interaction with the overall encoding of the file at the XML level. For the XAML language specification definition, see [MS-XAML] Sections 7.2.7 and 7.4.1.
For CLR backing, the x:String
primitive corresponds to xref:System.String.
String and char types have interaction with the overall encoding of the file at the XML level. For the XAML language specification definition, see [MS-XAML] Sections 7.2.6.
For CLR backing, the x:Decimal
primitive corresponds to xref:System.Decimal.
XAML parsing is inherently done under en-US
culture. Under en-US
culture, the correct separator for the components of a decimal is always a period (.
) regardless of culture settings of the development environment, or of the eventual client target where the XAML is loaded at run time.
For the XAML language specification definition, see [MS-XAML] Sections 7.2.14 and 7.4.8.
For CLR backing, the x:Single
primitive corresponds to xref:System.Single.
In addition to the numeric values, text syntax for x:Single
also permits the tokens Infinity
, -Infinity
, and NaN
. These tokens are treated as case sensitive.
x:Single
can support values in scientific notation form, if the first character in text syntax is e
or E
.
For the XAML language specification definition, see [MS-XAML] Sections 7.2.8 and 7.4.2.
For CLR backing, the x:Double
primitive corresponds to xref:System.Double.
In addition to the numeric values, text syntax for x:Double
permits the tokens Infinity
, -Infinity
, and NaN
. These tokens are treated as case sensitive.
x:Double
can support values in scientific notation form. Use the character e
or E
to introduce the exponent portion.
For the XAML language specification definition, see [MS-XAML] Sections 7.2.9 and 7.4.3.
For CLR backing, the x:Int16
primitive corresponds to xref:System.Int16 and x:Int16
is treated as signed. In XAML, the absence of a plus (+
) sign in text syntax is implied as a positive signed value.
For the XAML language specification definition, see [MS-XAML] Sections 7.2.11 and 7.4.5.
For CLR backing, the x:Int32
primitive corresponds to xref:System.Int32. x:Int32
is treated as signed. In XAML, the absence of a plus (+
) sign in text syntax is implied as a positive signed value.
For the XAML language specification definition, see [MS-XAML] Sections 7.2.12 and 7.4.6.
For CLR backing, the x:Int64
primitive corresponds to xref:System.Int64. x:Int64
is treated as signed. In XAML, the absence of a plus (+
) sign in text syntax is implied as a positive signed value.
For the XAML language specification definition, see [MS-XAML] Sections 7.2.13 and 7.4.7.
For CLR backing, the x:TimeSpan
primitive corresponds to xref:System.TimeSpan.
XAML parsing for time-date format is inherently done under en-US
culture.
For the XAML language specification definition, see [MS-XAML] Sections 7.2.16 and 7.4.10.
For CLR backing, the x:Uri
primitive corresponds to xref:System.Uri.
Checking for protocols is not part of the XAML definition for x:Uri
.
For the XAML language specification definition, see [MS-XAML] Sections 7.2.15 and 7.4.9.
For CLR backing, the x:Byte
primitive corresponds to xref:System.Byte. A xref:System.Byte / x:Byte
is treated as unsigned.
For the XAML language specification definition, see [MS-XAML] Sections 7.2.10 and 7.4.4.
For CLR backing, the x:Array
primitive corresponds to xref:System.Array.
You can define an array in XAML 2006 by using a markup extension syntax; however, the XAML 2009 syntax is a language-defined primitive that does not require accessing a markup extension. For more information about XAML 2006 support, see x:Array Markup Extension.
For the XAML language specification definition, see [MS-XAML] Sections 7.2.18.
In WPF, you can use XAML 2009 features but only for XAML that is not markup-compiled. Markup-compiled XAML for WPF and the BAML form of XAML do not currently support the XAML 2009 keywords and features.
A scenario where you can use XAML 2009 features together with WPF is if you author loose XAML and you then load that XAML into a WPF runtime and object graph with xref:System.Windows.Markup.XamlReader.Load%2A?displayProperty=nameWithType. The WPF xref:System.Windows.Markup.XamlReader?displayProperty=nameWithType and its xref:System.Windows.Markup.XamlReader.Load%2A can process XAML 2009 language keywords and features into a valid object graph representation.