The Silverlight and XAML Namespace Declarations

Within the root element of many XAML files, there are two xmlns declarations. The first declaration maps the overall Silverlight namespace as the default:

xmlns="http://schemas.microsoft.com/client/2007"

The second declaration maps a separate XML namespace for XAML, mapping it (typically) to the x: prefix:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

The relationship between these declarations is that XAML is a language definition, and Silverlight is one implementation that uses XAML as a language. Silverlight in particular uses a strict subset of XAML. The XAML language specifies certain language elements, and each of these should be accessible through XAML processor implementations working against the XAML namespace.

The Silverlight implementation of XAML and its intended programming model generally uses the default XML namespace for its own XAML vocabulary and uses a separate mapped prefix for the markup syntax expected in the Silverlight subset of the XAML namespace. By convention that prefix is x:, and this same x: convention is followed by project templates, sample code, and the documentation of language features within this documentation set. The XAML namespace defines several commonly used features that are necessary even for basic Silverlight-based applications. For instance, in order to join any code-behind to a XAML file through a partial class, you must name that class as the x:Class attribute in the root element of the relevant XAML file. Or, any element as defined in a XAML page that you wish to access as a keyed resource in a ResourceDictionary must have the x:Key attribute set on the object element in question.

Mapping to Custom Classes and Assemblies

You can map an XML namespace to an assembly by using a series of tokens within an xmlns prefix declaration, similar to how the XAML namespace value is mapped to the x: prefix.

The syntax takes the following possible named tokens and following values:

clr-namespace: The common language runtime (CLR) namespace declared within the assembly that contains the public types to expose to XAML usage. assembly= The assembly that contains some or all of the referenced CLR namespace.

Note that the character separating the clr-namespace token from its value is a colon (:) whereas the character separating the assembly token from its value is an equals sign (=). The character to use between these two tokens is a semicolon. Do not include whitespace anywhere within the mapping value. For example:

xmlns:custom="clr-namespace:SDKSample;assembly=SDKSampleLibrary"

Mapping to Current Assemblies

assembly can be omitted if the clr-namespace referenced is defined within the same assembly as the application code that references the custom classes. Or, an equivalent syntax for this case is to specify assembly=, with no string token following the equals sign.

Partial classes do not need to be mapped; only classes that are not the partial class of a page in your application need to be mapped if you intend to reference them as elements in XAML.