Why are there XAML namespaces that are URLS?

In Silverlight/WPF xaml at the top of the code you have your namespace/import type declarations. I can easily understand how these declarations can point to an assembly so that the types etc can be loaded from it. What I don't understand (and what I haven't really thought about up to now) is how these namespaces work when they point to a url, eg

http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit

Looking at this URL gives me an error so doesn't tell me anything.


There's an attribute you can use in the code of your referenced assembly that maps a Uri to your code namespaces:

[XmlnsDefinitionAttribute("http://yournamespace/", "Your.Assembly.Namespace")]

You can include multiple of these attributes, typically in your AssemblyInfo.cs , allowing multiple code namespaces to be referenced by a single Uri namespace in Xaml.

This makes your namespace declarations more compact (since you can omit the assembly name). It also allows you some flexibility in reorganizing namespaces in the referenced assembly without breaking your markup.

EDIT: for example, if you point Reflector at the PresentationCore assembly, you can see attributes such as this at the assembly level:

[assembly: 
    XmlnsDefinition( "http://schemas.microsoft.com/netfx/2007/xaml/presentation"
                   , "System.Windows.Ink") ]

This is how the Uri import gets mapped to code namespaces.


As far as I know they are URLs only out of convention, any unique identifier would do.

If you check HTML doctypes they are exactly the same, as in not actually loading :) For example: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd or http://www.w3.org/TR/html4/strict.dtd

It makes no sense why isn't anything on these URLs though, would be nice to have some actual references...

链接地址: http://www.djcxy.com/p/34568.html

上一篇: Flex:自定义项目渲染器对于Combobox控件,截断文本

下一篇: 为什么存在URLS的XAML命名空间?