微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WPF,Silverlight 中的 xmlns,xmlns:x

我们在每一个XAML文件中都可以看到下面的信息:

Silverlight应用
<
UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > </UserControl>
WPF应用
<
Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> </Grid> </Window>

      XAML文件首先是一个XML文件。为了验证自己和子元素的合法性,即保证在XML文档中的元素和属性名字的合法性,XML规范了XML命名空间,参看下面文档:

http://www.opendl.com/openxml/w3/TR/xml-names/xml-names-gb.html

      上面例子中,xmlns 属性专门指认的 xmlns 命名空间。在认的 xmlns 命名空间中,可以不使用前缀指定标记中的对象元素。目前对于大多数的 WPF 应用程序以及 SDK 的 WPF 部分中给出的几乎所有示例版本的WPF,Silverlight 2.0 (含)以后的开发工具, 认的 xmlns 命名空间均映射到 WPF 命名空间 http://schemas.microsoft.com/winfx/2006/xaml/presentation

      xmlns:x 属性指示另外一个 xmlns 命名空间,该命名空间映射 XAML 语言命名空间 http://schemas.microsoft.com/winfx/2006/xaml 。在具有此映射的文件标记中引用时,XAML 规范定义的所需语言组件带有 x: 前缀。

如下图所示:

<Page 根元素的开始对象元素
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 认 (WPF) 命名空间
就类似于如下的C#代码
using System.Windows;
using System.Windows.Automation 
using System.Windows.Controls;
using System.Windows.Controls.Primitives 
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms.Integration 
using System.Windows.Ink 
using System.Windows.Media.Animation 
using System.Windows.Media.Effects 
using System.Windows.Media.Media3D 
using System.Windows.Media.textformatting 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 这是XAML语言命名空间,用于映射System.Windows.Markup命名空间中的类型,而且它也定义了XAML编译器或解析器中的一些特殊的指令。这些指令通常是作为XML元素的特性出现的,因此它们看上去像宿主元素的属性,但实际上并不是如此。
x:Class="MyNamespace.MyPageCode" 分部类声明,它将标记连接到此分部类中定义的任何代码隐藏
> 根的对象元素的末尾,但由于页面包含子元素,因此尚未结束

 

参考资料:

WPF学习笔记1:XAML之NameSpace
http://www.cnblogs.com/jacksonyin/archive/2008/02/25/1080336.html

HTML xmlns 属性
http://www.w3school.com.cn/tags/tag_prop_xmlns.asp

XAML 概述
http://msdn.microsoft.com/zh-cn/library/ms752059.aspx

《WPF揭秘》 2.3  命名空间
http://book.csdn.net/bookfiles/677/10067721293.shtml

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐