This is a mirror of official site: http://jasper-net.blogspot.com/

A guide to cleaner XAML with custom namespaces and prefixes (WPF/Silverlight)

| Tuesday, October 5, 2010
Introduction
When working with any type of application it's a good idea to split up your solution in multiple projects (assemblies) and namespaces. As your project grows you'll see your amount of namespaces grow with it. And if you plan to use classes / controls from these namespaces in your XAML code, you'll have to declare them with the following syntax:

xmlns:PREFIX="clr-namespace:NAMESPACE"

An example could be:

xmlns:conv="clr-namespace:Sandworks.Silverlight.NamespaceExample.Converters"

If you are referencing an other assembly, you'll also need to add the assembly name:

xmlns:PREFIX="clr-namespace:NAMESPACE;assembly=ASSEMBLYNAME"

For example:

xmlns:lib="clr-namespace:Sandworks.Silverlight.NamespaceExample.ClassLibrary.Converters;assembly=Sandworks.Silverlight.NamespaceExample.ClassLibrary"

Some namespaces are added by default when you add a new XAML control in your project (be it a UserControl or a Page).
This is how it should look like:

<UserControl x:Class="Sandworks.Silverlight.NamespaceExample.MainPage"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

But, as stated before, when your project starts growing and you need to work with different namespaces and assemblies your references might start piling up and your XAML code gets bloated.

Read more: Sandrino Di Mattia

Posted via email from .NET Info

0 comments: