c# - 在不定义新 xmlns 的情况下访问 XAML 命名空间的子命名空间

标签 c# wpf

根据 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 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.

关于c# - 在不定义新 xmlns 的情况下访问 XAML 命名空间的子命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24680868/

相关文章:

c# - 具有非阻塞超时设置的 TcpClient.ConnectAsync 或 Socket.BeginConnect

c# - 在C#中使用继承类作为实例List

c# - 使用 MVVM Light 创建通用用户控件

c# - 如何从 UWP(又名 .NET Core)中的类型对象获取程序集

c# - 条件样式 : if (0 == resultIndex) vs if (resultIndex ==0)

c# - WCF RIA 服务 - 返回两个已定义类的自定义类

wpf - WPF 中的免费日历/调度程序控件

c# - 与 ViewModel 共享 EntityFramework 上下文

c# - 使用集合时如何在MVVM中同步数据

wpf - 绑定(bind) ="{Binding (0)}"是什么意思?