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, e.g.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With