xml - WPF - Defining a xmlns based on another xmlns
问题描述
Is there any way to declare a namespace like this :
xmlns:views="clr-namespace:xxx.xxx.Views"
xmlns:someNestedViews="views.SomeNestedView"
The objective is to speed up nested/repeated xmlns declarations and make them easier to read/maintain.
解决方案
不,您需要包含整个 CLR 命名空间:xmlns:someNestedViews="xxx.xxx.Views.SomeNestedView"
. 该clr-namespace:
语法将 XAML 命名空间映射到 CLR 命名空间。它不映射到另一个 XML 命名空间。
如果您是命名空间中的类的作者,则Views
可以使用XmlnsDefinitionAttribute指定 XAML 命名空间和几个不同的 CLR 命名空间之间的映射,例如:
[assembly: XmlnsDefinition("http://yourlibrary.com/", "xxx.xxx.Views.")]
[assembly: XmlnsDefinition("http://yourlibrary.com/", "xxx.xxx.Views.SomeNestedView")]
这减轻了 XAML 中的负担:
xmlns:viewsAndNestedViews="http://yourlibrary.com/"
推荐阅读
- python - Python - 刽子手
- php - 将数组作为 POST 请求参数发送到 PHP - Swift
- laravel - DELETE 方法在 PHP 变量中不起作用
- android - 我的 colors.xml 文件没有显示主题颜色。一切都是灰色的。如何解决这个问题?
- sapui5 - 使用 SAP UI5 动态呈现视图元素
- c# - 收到错误“Type Universe 无法解析程序集:System.Runtime,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a。”
- deployment - Sylius:“缓存:清除”超时
- r - 'ivreg' 代码(来自 AER 包)适用于较弱的 PC,但不适用于较强的 PC
- entity-framework-core - 实体框架核心数据迁移和在 EF 之外创建的表
- node.js - Dialogflow 中的任何 RichResponse 是否有可用的回调