This afternoon I was working on Innoveo Skye Editor which is a WPF application written in C#.

The application is using Telerik RadControls for WPF.

I was facing the issue of having more and more namespace declarations like the following for RadInput and Rad:

<Window x:Class="skyeEditor.View.Dialogs.ProductSettingsDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:RadInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
        xmlns:Rad="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"

Searching for a solution I thought of ASP.NET in which you can declare in the web.config things like that:

<pages pageBaseType=”System.Web.Mvc.WebViewPage”>
  <namespaces>
    <add namespace=”MyNamespace” />

My goal was to have one namespace declaration for example telerik and be able to use it in all my XAML files without having to declare too much.

So I started an online discussion with Laurent Bugnion who has always shown me the good direction, which in this case is the

XmlnsDefinitionAttribute Class

Followed by an article from Sandino Di Mattia about “A Guide to Cleaner XAML with Custom Namespaces and Prefixes (WPF/Silverlight)”.

Using the idea I was able to add the following to the AssemblyInfo.cs of my own project:

[assembly: XmlnsDefinition("telerik",
                           "Telerik.Windows.Controls",
                           AssemblyName = "Telerik.Windows.Controls")]

[assembly: XmlnsDefinition("telerik",
                           "Telerik.Windows.Controls",
                           AssemblyName = "Telerik.Windows.Controls.Input")]

[assembly: XmlnsDefinition("telerik",
                           "Telerik.Windows.Controls",
                           AssemblyName = "Telerik.Windows.Controls.Navigation")]

[assembly: XmlnsDefinition("telerik",
                           "Telerik.Windows.Controls",
                           AssemblyName = "Telerik.Windows.Controls.RibbonView")]

And then my XAML file declaration looks like that:

<Window x:Class="skyeEditor.View.Dialogs.ProductSettingsDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"

And I can use everywhere for all Telerik RadControls for WPF with the prefix telerik

<telerik:RadComboBox ItemsSource="{Binding ProductNodeLabels}"
                        SelectedItem="{Binding SelectedProductNodeLabel}"
                        Margin="0,0,0,5" />

A little step but a nice improvement!