views:

32

answers:

1

I have read that xml namespace value is any arbitrary string value.

But in the next paragraph in the book, I have read that : This namespace (xmlns:x) contains the required language components that are defined in the xaml specification, such as the ability to set an objects's name.

Please anyone clear me this line.

Because this string does not map to any namespace or assembly or anything in .net framework, then how can this namespace contain the language components or types such as Name in x:Name ?

<UserControl x:class="Chapter03.Page" 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  width="400" height="300">

            <Grid x:Name="LayoutRoot" Backgroud="White">
            </Grid>

</UserControl>
+2  A: 

To the contrary, these namespaces do have a meaning and do map to CLR namespaces. For example, the System.Windows assembly contains the following attributes:

[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Controls")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Controls.Primitives")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Data")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Documents")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Ink")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Input")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Media")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Media.Animation")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Media.Effects")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Media.Imaging")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Media.Media3D")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Shapes")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Automation")]
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml", "System.Windows.Markup")]

These attributes map the xml namespace "http://scemas.microsoft.com/winfx/2006/xaml/presentation" to the set of CLR namespaces defined by the attributes.

You can also explicitly reference a clr namespace (without using the XmlnsDefinitionAttribute) using a string like "clr-namespace:System.Windows.Controls;assembly=System.Windows". XmlnsDefinitionAttribute allows multiple CLR namespaces to be mapped into a single Xml namespace.

xmlns:x is a special pre-defined namespace that contains the XAML language features (e.g. x:Name, x:Key, x:Class, etc.) that don't necessarily map to CLR types.

David.Poll