#73 – Multiple Namespaces Using Prefixes
September 23, 2010 Leave a comment
You can use multiple namespaces in a XAML file, allowing you to use names from multiple namespaces in the same file.
When you use more than one namespace, you need to associate all but one of the namespaces with a prefix, which you use to qualify names belonging to the prefixed namespaces. You can include one namespace (the default namespace) that does not include a prefix.
In WPF, two namespaces are typically used:
<Application x:Class="WpfApplication1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml">
In this example, the second namespace uses the “x” prefix, declaring the prefix as part of the xmlns attribute. All names qualified with the “x” prefix, e.g. x:Class, belong to this namespace.
The first namespace in the example does not include a prefix. All names in the XAML file not qualified with a prefix are assumed to belong to this namespace–e.g. StartupUri.