WPF,Silverlight 中的 xmlns,xmlns:x

https://blog.csdn.net/ghj1976/article/details/4856151

我们在每一个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: 前缀。

如下图所示:

  <td width="413">根元素的开始对象元素 </td>
</tr><tr><td width="501"><span class="code">xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span> </td>

  <td width="413">默认 (WPF) 命名空间 
    <br>就类似于如下的C#代码: 

    <br><pre><span style="color:#0000ff;">using</span> System.Windows;
<Page

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

  <td width="413">这是XAML语言命名空间,用于映射System.Windows.Markup命名空间中的类型,而且它也定义了XAML编译器或解析器中的一些特殊的指令。这些指令通常是作为XML元素的特性出现的,因此它们看上去像宿主元素的属性,但实际上并不是如此。</td>
</tr><tr><td width="501"><span class="code">x:Class="MyNamespace.MyPageCode"</span> </td>

  <td width="413">分部类声明,它将标记连接到此分部类中定义的任何代码隐藏 </td>
</tr><tr><td width="501"><span class="code">&gt;</span> </td>

  <td width="413">根的对象元素的末尾,但由于页面包含子元素,因此尚未结束 </td>
</tr></tbody></table></div><p>&nbsp;</p>

参考资料:

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

猜你喜欢

转载自blog.csdn.net/baidu_37503452/article/details/91428765