XmlnsDefinition for a Cool Namespace Mapping
In XAML, when you want to reference a CLR type, you have to add a namespace mapping that maps the XML namespace to the CLR namespace, like so:
xmlns:local="clr-namespace:MyTestApp.Controls;assembly=TestApp.Controls"
However the Types from PresentationFramework and PresentationCore are included differently, like so:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
What I like about this declaration is the fact that it hides all the CLR-namespaces that are automatically imported. This is possible because inside PresentationFramework.dll (and some in PresentationCore.dll), we have a bunch of assembly attributes, namely the XmlnsDefinitionAttribute:
[assembly:
XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation",
"System.Windows")] [assembly:
XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation",
"System.Windows.Data")] [assembly:
XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation",
"System.Windows.Navigation")] [assembly:
XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation",
"System.Windows.Shapes")] [assembly:
XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation",
"System.Windows.Documents")] [assembly:
XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation",
"System.Windows.Controls")]
This does the mapping from the CLR namespace to the XML namespace. So instead of having a list of xmlns mappings in your XAML file, you just have one, of the formxmlns:x=“http://schemas.microsoft.com/winfx/2006/xaml/presentation”. This not only simplifies the mapping declarations but it is also easier to remember. So say for example your company created a bunch of cool WPF controls; you could then have a XmlnsDefinitionAttribute in the Control Library as:
[assembly: XmlnsDefinition("http://www.my-company.com/wpf",
"MyCompany.Controls")]
Then your users could use these controls in their XAML files simply by including the namespace mapping:
xmlns:mc="http://www.my-company.com/wpf"
Now isn’t that a cooler way of declaring the XML namespace!
XmlnsDefinition for a Cool Namespace Mapping的更多相关文章
- 菜鸟学Struts2——Struts工作原理
在完成Struts2的HelloWorld后,对Struts2的工作原理进行学习.Struts2框架可以按照模块来划分为Servlet Filters,Struts核心模块,拦截器和用户实现部分,其中 ...
- Phoenix综述(史上最全Phoenix中文文档)
个人主页:http://www.linbingdong.com 简书地址:http://www.jianshu.com/users/6cb45a00b49c/latest_articles 网上关于P ...
- Struts2 源码分析——Result类实例
本章简言 上一章笔者讲到关于DefaultActionInvocation类执行action的相关知识.我们清楚的知道在执行action类实例之后会相关处理返回的结果.而这章笔者将对处理结果相关的内容 ...
- Struts2 源码分析——Action代理类的工作
章节简言 上一章笔者讲到关于如何加载配置文件里面的package元素节点信息.相信读者到这里心里面对struts2在启动的时候加载相关的信息有了一定的了解和认识.而本章将讲到关于struts2启动成功 ...
- Struts2 源码分析——调结者(Dispatcher)之执行action
章节简言 上一章笔者写关于Dispatcher类如何处理接受来的request请求.当然读者们也知道他并非正真的执行action操作.他只是在执行action操作之前的准备工作.那么谁才是正真的执行a ...
- 浅谈:深入理解struts2的流程已经spring和struts2的整合
第一步:在tomcat启动的时候 1.在tomcat启动的时候,首先会加载struts2的核心过滤器StrutsPrepareAndExecuteFilter <filter> <f ...
- Struts2与Ajax的整合
整合: 导入jar包 sturts2-json-plugin-2.1.8.1.jar 说明: 在该jar包中有struts-plugin.xml文件 <struts> ...
- Struts2.3.15.1源码浅析
Struts2 两大运行主线: 1.初始化主线:初始化主线主要是为Struts2创建运行环境(此处的环境与Struts2身处的Web环境是有区别的),初始化入口StrutsPrepareAndExec ...
- WS+MQ+WCF+EF(Code First)
前言 有段时间没有更新博文了,一直在忙工作很少有时间静下心来继续研究点东西,说来也惭愧,归咎原因最主要的还是因为懒惰.空想也是不管用的,有时候很多想法被扼杀到了摇篮里,还没开始做就放弃了,这是多数人会 ...
随机推荐
- Visual F# Power Tools 简单介绍
Visual F# Power Tools 简单介绍 Auto-generating XmlDoc 当在函数定义的前面输入 ///< 以后.会自己主动生成 XML 文档.并会自己主动提取函数中的 ...
- 如何在JS数组特定索引处指定位置插入元素?
如何在JS数组特定索引处指定位置插入元素? 需求: 将一个元素插入到现有数组的特定索引处.听起来很容易和常见,但需要一点时间来研究它. // 原来的数组var array = ["one&q ...
- ASP.NET CORE中控制器内return HTML 内容自动编码问题
以前ASP.NET MVC中在控制器中直接 return Content( "<h1>测试测试</h1>"); 在前台VIEW上就显示加粗的文字了,但是在A ...
- distill 来自google,openai,deepmind,YC research
https://distill.pub/ https://colah.github.io/
- Techniques for HA IT Management
7. Techniques That Address Multiple Availability Requirements Redundancy Hardware Redundancy Example ...
- 利用es-checker检测当前node对ES6的支持情况
ode.js发展非常快,对es6特性的支持也越来越良心,但node.js版本很多,各版本对es6的支持度都不一样,为了能清晰的了解各版本对es6特性的支持,需要有一个工具能提供比较清晰的支持说明,甚至 ...
- vim学习笔记(12):在vim中修改文件编码,解决vim 打开乱码
在linux 中查看文件编码可以通过以下几种方式: 一.查看文件编码 1.查看文件编码file命令 :file ip.txt ip.txt: UTF-8 Unicode text, with esca ...
- spring 过滤器
Spring的web包中中有很多过滤器,这些过滤器位于org.springframework.web.filter并且理所当然地实现了javax.servlet.Filter,不过实现的方式有以下几类 ...
- c字符输出
#include<stdio.h> int main() { char c1,c2; c1 = ; c2 = ; printf("c1 = %c,c2 = %c\n", ...
- in linux system of ftp command
一口流利的english title 常用命令: ftp baidu.com ftp>ls ftp>cd directory ftp>get filename 下载 ftp>p ...