2010-07-25 85 views
1

我已阅读,XML命名空间值是任意字符串值。但是在本书的下一段中,我读到:这个命名空间(xmlns:x)包含在xaml规范中定义的所需语言组件,例如设置对象名称的能力。混淆XAML命名空间值

请人清除了我这条线。

因为这个字符串不映射到.NET Framework中的任何命名空间或组装或任何东西,那么怎么能这个命名空间包含x中的语言成分或类型,如名称:名称?

<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> 
+0

指定版本的Xaml解析已3和4之间改变 – AnthonyWJones 2010-07-26 11:57:53

回答

3

恰恰相反,这些名称空间确实有意义并映射到CLR命名空间。例如,System.Windows组件包含以下属性:

[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")] 

这些属性映射的XML名称空间“http://scemas.microsoft.com/winfx/2006/xaml/presentation”到该组由所述属性进行定义的CLR名称空间。

您还可以使用类似“clr-namespace:System.Windows.Controls; assembly = System.Windows”的字符串显式引用clr命名空间(不使用XmlnsDefinitionAttribute)。 XmlnsDefinitionAttribute允许将多个CLR名称空间映射到单个Xml名称空间中。

xmlns:x是一个特殊的预定义名称空间,它包含不一定映射到CLR类型的XAML语言功能(例如x:Name,x:Key,x:Class等)。