博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[XAML]命名空间xmlns
阅读量:7239 次
发布时间:2019-06-29

本文共 1799 字,大约阅读时间需要 5 分钟。

在编写WPF的XAML文件时,我们都会看到系统生成的默认文件里,包含如下东西:

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 那么他们是什么意思呢?

xmlns是XAML引用的命名空间

不带冒号的,是作为默认命名空间,例如:

 带冒号的,在XML里就需要用前缀来引用,例如:

 当你复制上面引用的地址到浏览器里打开时,是访问不到的。

它们并不是真正存在于网络上,而是存在于程序集里。

用Reflector反射PresentationFramework程序集

注意看程序集的信息,里面有一堆这样的代码:

[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Controls")][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.Shapes")][assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Shell")][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.Data")][assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows")][assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Controls.Primitives")][assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Media.Animation")][assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Input")][assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Media")]

这些代码的作用就是把那些命名空间合并到一个统一的命名空间里,方便调用。

我们在自己的程序集里也可以这样用,只要修改AssemblyInfo.cs就可以了。

然后我们在XAML里添加命名空间,就会看到自己定义的命名空间了。

转载于:https://www.cnblogs.com/Kation/archive/2013/05/02/xaml-xmlns.html

你可能感兴趣的文章
python模块之logging模块
查看>>
Cron 表达式详解和案例
查看>>
HDU 3535 AreYouBusy
查看>>
磁盘管理之磁盘组成
查看>>
Page LSNs and Recovery
查看>>
select 0 与select (0)
查看>>
maven安装
查看>>
SQLServer 2008 还原数据库备份不兼容
查看>>
Oracle之into
查看>>
【mac】mac上安装JDK
查看>>
JS面试题(一)
查看>>
C语言文件I/O
查看>>
python 使用__future__
查看>>
c# 串口问题
查看>>
低配置电脑播放 flash 视频时 占 cpu 资源过高的解决方法
查看>>
linux下ssh/sftp配置和权限设置
查看>>
js面向对象编程两个主要点
查看>>
Xml通用操作类
查看>>
CSS常见以及解决兼容办法
查看>>
含参数的二次不等式的解法【中级和高阶辅导】
查看>>