Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between a schema namespace and an assembly reference in WPF?

Tags:

wpf

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

like image 442
Micah Avatar asked Oct 07 '08 17:10

Micah


1 Answers

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")]
like image 124
user7116 Avatar answered Sep 22 '22 01:09

user7116