简体   繁体   中英

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:

I am trying to access the namespace NineGridViewer.ValidationRules within my XAML. I currently have the namespace definition 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?

If you have access to the assembly defining those classes, you can create custom XML namespaces using an attribute:

WPF defines a CLR attribute that is consumed by XAML processors in order to map multiple CLR namespaces to a single XAML namespace. This attribute, XmlnsDefinitionAttribute , is placed at the assembly level in the source code that produces the assembly. 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.

The XmlnsDefinitionAttribute takes two parameters: the XML/XAML namespace name, and the CLR namespace name. More than one XmlnsDefinitionAttribute can exist to map multiple CLR namespaces to the same XML namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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