简体   繁体   English

访问XAML命名空间的子命名空间而不定义新的xmlns

[英]Accessing sub-namespaces of a XAML namespace without defining a new xmlns

This might just be impossible by the nature of XAML but this is my situation: 这可能是XAML的本质所不可能的,但这是我的情况:

I am trying to access the namespace NineGridViewer.ValidationRules within my XAML. 我试图在我的XAML中访问命名空间NineGridViewer.ValidationRules I currently have the namespace definition xmlns:nineGridViewer="clr-namespace:NineGridViewer" . 我目前有命名空间定义xmlns:nineGridViewer="clr-namespace:NineGridViewer" Is it necessary to define a completely new namespace to access the ValidationRules namespace or is it possible to use my nineGridViewer xmlns to access subnamespaces? 是否有必要定义一个全新的命名空间来访问ValidationRules命名空间,或者是否可以使用我的nineGridViewer xmlns来访问子命名空间?

If you have access to the assembly defining those classes, you can create custom XML namespaces using an attribute: 如果您可以访问定义这些类的程序集,则可以使用以下属性创建自定义XML名称空间

WPF defines a CLR attribute that is consumed by XAML processors in order to map multiple CLR namespaces to a single XAML namespace. WPF定义了XAML处理器使用的CLR属性,以便将多个CLR命名空间映射到单个XAML命名空间。 This attribute, XmlnsDefinitionAttribute , is placed at the assembly level in the source code that produces the assembly. 此属性XmlnsDefinitionAttribute放置在生成程序集的源代码中的程序集级别。 The WPF assembly source code uses this attribute to map the various common namespaces, such as System.Windows and System.Windows.Controls , to the http://schemas.microsoft.com/winfx/2006/xaml/presentation namespace. WPF程序集源代码使用此属性将各种常见名称空间(如System.WindowsSystem.Windows.Controls映射到http://schemas.microsoft.com/winfx/2006/xaml/presentation名称空间。

The XmlnsDefinitionAttribute takes two parameters: the XML/XAML namespace name, and the CLR namespace name. XmlnsDefinitionAttribute有两个参数:XML / XAML命名空间名称和CLR命名空间名称。 More than one XmlnsDefinitionAttribute can exist to map multiple CLR namespaces to the same XML namespace. 可以存在多个XmlnsDefinitionAttribute以将多个CLR命名空间映射到同一XML命名空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM