Wednesday, May 22, 2013

How to create custom XMLNS namespaces to keep your XAML clean?

Inline image 1 Inline image 2


XAML namespace is an extension of XML namespace and conventionally written as "xmlns" in XAML pages. We use it on all XAML pages in Silverlight, Windows Phone, Windows 8, WPF related technologies to better reference assemblies and namespaces.
 
In this post we will learn more about this XMLNS namespace and the way to customize it for a cleaner XAML page. Interested to know it? Continue reading and share your feedback about the post.
 
What is a XAML Namespace?

Let us first know a little about XAML namespace syntax, the convention of using URIs as namespace identifiers and the prefixes to provide a meaningful reference to single or multiple namespaces for the same source. You can create a XAML namespace by providing a series of tokens or a custom URL that suits your convention.
 
The syntax that the token based xmlns uses, has the following token parts:

clr-namespace: The namespace declared within the assembly that exposes public types as elements.

assembly= The assembly name that contains some or all of the referenced namespace as mentioned above.

For example, xmlns:controls="clr-namespace:KunalChowdhury.Controls;assembly=KunalChowdhury.Dashboard". Here the namespace is "KunalChowdhury.Controls" present under the assembly "KunalChowdhury.Dashboard.dll". In case you are referencing the namespace from the same assembly, you don't have to provide the assembly token as it knows that you are using the element from the same assembly. The separator that extracts clr-namespace is colon ":" whereas the separator that extracts assembly is equal sign "=".
...
...

Inline image 3



QR: Inline image 4