tags:

views:

680

answers:

2

Why is it that there are two kinds of references in xaml.

One looks like this:

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

But mine look like this:

xmlns:WPFToolKit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"

Why can't I do this:

xmlns:local="http://myschema.mydomain.com/MyControlNamespace

Thanks to ixlettervariables for the answer. Here's a detailed explanation here

+6  A: 

The second instance is basically an unmapped, but explicit reference to a namespace in an assembly. The first instance is a mapped reference to a namespace in some assembly referenced by your project. XAML Namespaces and Namespace Mapping, over at MSDN explains this in more detail:

WPF defines a CLR attribute that is consumed by XAML processors in order to map multiple CLR namespaces to a single XML namespace. This attribute, XmlnsDefinitionAttribute, is placed at the assembly level in the source code that produces the assembly. The WPF assembly source code uses this attribute to map the various common namespaces, such as System.Windows and System.Windows.Controls, to the http://schemas.microsoft.com/winfx/2006/xaml/presentation namespace.

Therefore, by adding the following to your assembly you could do just that:

[assembly:XmlnsDefinition("http://myschema.mydomain.com/MyControlNamespace", "My.Control.Namespace")]
sixlettervariables
A: 

The schema reference is used for the standard XAML elements, which the compiler knows how to map directly to built-in WPF classes.

The CLR namespace reference is a hint for the compiler which assmebly and namespace to look for when mapping the XML elements in your namespace namespace to your CLR/WPF classes.

Franci Penov