When we want to declaratively use our custom controls or reference the types we defined in XAML, we should declare the XML namespace to map to the CLR namespace in which the controls and types are defined as the following XAML snippt demonstrates:

<Page x:Class="Test.MainWindow"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:cc="clr-namespace:Sheva.Windows.Controls;assembly=AvalonLib"/>

Recently, I am heavily engaged with writing a resuable WPF control library, and quite often I need to create some pages to test those controls I create, so ever now and then I have to use the cumbersome syntax like above to declare the XML namespace, personally I don't like the syntax, and I thought Microsoft WPF team should come up with a more elegant way of doing it, and in actuality, they did introduce an alternative to do it since the CTP releases. there is a custom attribute called XmlnsDefinitionAttribute in the System.Windows.Markup namespace which allows you to apply to the assembly which contains the types and controls the XAML code would reference.the built-in WPF assemblies such as WindowsBase.dll, PresentationCore.dll, and PresentationFramework.dll all have this attribute applied, and all have http://schemas.microsoft.com/winfx/2006/xaml/presentation namespace mapped with the CLR namespaces introduced by them. and of cause you can use this attribute in your own project, just open the AssemblyInfo.cs file, and append the following directive:

[assembly: XmlnsDefinition("http://schemas.sheva.com/wpf/", "Sheva.Windows.Controls")]

Then you can declare the namespace alias in XAML this way:

<Page x:Class="Test.MainWindow"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:cc="http://schemas.sheva.com/wpf/"/>

Wow, this is a bit like the built-in xmlns declaration indeed, really really cool indeed:)

XmlnsDefinitionAttribute Is Pretty Nifty的更多相关文章

  1. 定时Job在IIS中潜在危险-IIS 定期回收

    引言 有时我们会在IIS中启用一些定时服务,但是你必须清楚IIS会定期回收Asp.net的应用程序的.首先来看IIS啥时候回收APPDomain.   APPDomain 回收时机 There are ...

  2. Java资源大全中文版(Awesome最新版)

    Awesome系列的Java资源整理.awesome-java 就是akullpp发起维护的Java资源列表,内容包括:构建工具.数据库.框架.模板.安全.代码分析.日志.第三方库.书籍.Java 站 ...

  3. thrift:swift项目笔记

    先声明:此swift不是Apple公司的那个swift开发语言,而是facebook的另一个开源项目. facebook的thrift IDL文件,如果默认用thrift -gen java生成jav ...

  4. Beennan的内嵌汇编指导(译)Brennan's Guide to Inline Assembly

    注:写在前面,这是一篇翻译文章,本人的英文水平很有限,但内嵌汇编是学习操作系统不可少的知识,本人也常去查看这方面的内容,本文是在做mit的jos实验中的一篇关于内嵌汇编的介绍.关于常用的内嵌汇编(AT ...

  5. Beginning Scala study note(6) Scala Collections

    Scala's object-oriented collections support mutable and immutable type hierarchies. Also support fun ...

  6. 学习C++.Primer.Plus 10 对象和类

    1.类的声明和定义 类的声明和定义. 类声明的格式如下: class className { private://private 是类对象的默认访问控制,因此,可以省略 data member del ...

  7. words

    conscious[英][ˈkɒnʃəs][美][ˈkɑnʃəs]consensus[英][kənˈsensəs][美][kənˈsɛnsəs] scious sensuswaterflood; de ...

  8. SCALA XML pattern attrbute(属性)

    from: Working with Scala's XML Support 虽然这个guy炒鸡罗嗦,但是还是讲到我要的那句话:  Because Scala doesn't support XML ...

  9. supervisor centos安装

    一.安装配置supervisor 1.安装python自动化工具    #yum install python-setuptools 2.#easy_install supervisor安装super ...

随机推荐

  1. .Net Core 部署到 CentOS7 64 位系统中的步骤

    建议使用 root 管理员账户操作 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务器一开机就启动服务器 上发 ...

  2. java基础8 构造函数和构造代码块

    一.构造函数 1 构造函数的作用 给对应的对象进行初始化. 2 构造函数的格式 修饰符 函数名(形式参数){ //函数名就是类名 函数体 } 举例说明: class Perosn{ private i ...

  3. PHP学习笔记之数组游标操作

    数组有N个单元,同时只能操作一个单元.比如循环时,只能一个一个单元读取他的值. 那么数组是怎么记住刚才读取的是哪个单元,接着读取下个单元的呢? 在数组内部,有一个指针,指针指向某一个单元. 每循环一个 ...

  4. Codeforces 822D My pretty girl Noora(最小素因子的性质)

    题目大意:一场选美比赛有N个人,可以分成N/x,每组x人.每组的比较次数为x(x-1)/2,f[N]为最后决出冠军所需的比较次数,可以通过改变x的值使f[N]改变.题目给出t,l,r(1 ≤ t &l ...

  5. HEVC代码记录(删除)

    得到编码残差  TEncSearch.cpp 4543:rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );

  6. css控制单行文本溢出

    1.溢出属性(容器的) overflow:visible/hidden(隐藏)/scroll/auto(自动)/inherit; visible:默认值,内容不会被修剪,会成现在元素框之外: hidd ...

  7. 怎么修改chrome浏览器的字体

    点击“自定义字体”可以修改字体风格.   如果习惯看微软雅黑的字体,我们可以点击“宋体”进入字体选择,拖动向下可以找到“微软雅黑”的字体,点击“微软雅黑”,然后再点击“完成”即可.   另外如果设置字 ...

  8. 【转】EventBus 3.0使用详解

    原文:https://www.jianshu.com/p/f9ae5691e1bb 01 前言 当我们进行项目开发的时候,往往是需要应用程序的各组件.组件与后台线程间进行通信,比如在子线程中进行请求数 ...

  9. 【PAT】1001. A+B Format (20)

    1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, the digits m ...

  10. LR 报错误: C interpreter run time error: Error -- Unresolved symbol : vuser_end解决方法

    Action.c(33): Error: C interpreter run time error: Action.c (33):  Error -- Unresolved symbol : vuse ...