根据 XAML 的性质,这可能是不可能的,但这是我的情况:
我正在尝试访问我的 XAML 中的命名空间 NineGridViewer.ValidationRules
。我目前有命名空间定义 xmlns:nineGridViewer="clr-namespace:NineGridViewer"
。是否需要定义一个全新的命名空间来访问 ValidationRules 命名空间,或者是否可以使用我的 nineGridViewer xmlns 来访问子命名空间?
最佳答案
如果您有权访问定义这些类的程序集,您可以 create custom XML namespaces使用属性:
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
andSystem.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.
关于c# - 在不定义新 xmlns 的情况下访问 XAML 命名空间的子命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24680868/