XAML的命名空间 - CSDN博客
原文:XAML的命名空间 - CSDN博客 一个最简单的XAML例子 xmlns后可以跟一个可选的映射前缀,之间用冒号分隔,如果没有写可选映射前缀,就意味着所有来自这个名称空间的标签都不用加前缀,这个没有映射前缀的名称空间称为“默认名称空间”,默认名称空间只能有一个。上面的例子中,Window和Grid都属于 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation声明的默认命名空间,而Class特征来自于
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>xmlns特征的语法格式如下:xmlns[:可选的映射前缀]="名称空间"
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml申明的命名空间,如果给 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation申明的命名空间加上一个前缀,那么代码必须修改成这样<n:Window x:Class="WpfApplication1.MainWindow"
xmlns:n="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<n:Grid>
</n:Grid>
</n:Window>
在C#中,如果要使用System.Windows.Controls名称空间里的Button类,需要先把包含System.Windows.Controls美林歌城空间的程序集PresentationFramework.dll通过添加引用的方式引用到项目中,然后再在C#代码的顶端输入using System.Windows.Controls;
在XAML如果需要使用Button类,也需要先添加对程序集的引用,然后在根元素的起始标签中写上一句:xmlns:c="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
x:Class这个属性的作用是当XAML解析器将包含它的标签解析成C#类后的类名,用Windows SDK自带的工具IL反汇编程序对编译出来的exe进行反汇编,可以发现生成了MainWindow类
在XAML中引用名称空间的语法是:
xmlns:映射名="clr-namespace:类库中名称空间的名字;assembly=类库文件名"
xmlns:common="clr-namespace:Common;assembly=MyLibrary"
xmlns;control="clr=namespace:Control;assembly=MyLibrary"
最新文章
- Linux下man手册使用
- MySQL 中的 FOUND_ROWS() 与 ROW_COUNT() 函数
- 2014江西理工大学C语言程序竞赛高级组
- [ Office 365 开发系列 ] 开发模式分析
- Java带包编译运行
- C#与java中的集合区别
- App_Code
- java.lang.SecurityException:Invalid signature file digest forManifest main attributes
- [笔记]我的Linux入门之路 - 03.Java环境搭建
- 进程控制fork与vfork
- Codeforces 803C. Maximal GCD
- @Autowired 与@Resource的区别(详细)
- centos7通过yum安装mysql,并授权远程连接 【转】
- VUE 前端项目优化方法
- Ubuntu忘记密码的解决办法
- [转载]java中io流关闭的顺序
- Unity打安卓包 Android 所有错误解决方案大全(几乎囊括所有打包错误 )
- poj1151 Atlantis &;&; cdoj 1600艾尔大停电 矩形面积并
- 流程控制(if、while、for)
- xcode没有ios7的模拟器
热门文章
- php实现字符串的排列(交换)(递归考虑所有情况)
- [RxJS] Use groupBy in real RxJS applications
- 不使用left-join等多表关联查询,只用单表查询和Java程序,简便实现“多表查询”效果
- 【codeforces 768A】Oath of the Night's Watch
- Eclipse Che安装入门和使用(一)
- 小强的HTML5移动开发之路(26)—— JavaScript回顾1
- C++程序员经常问的11个问题
- hexo改造
- Android菜鸟的成长笔记(16)——Service简介
- 基于Geoserver发布时间地图