现在的位置: 首页 > 综合 > 正文

无废话WPF系列1:XAML分析

2012年01月19日 ⁄ 综合 ⁄ 共 791字 ⁄ 字号 评论关闭

新建一个程序,我们来分析一下这段最简单的XAML

image

这个命名空间http://schemas.microsoft.com/winfx/2006/xaml/presentation是WPF的硬编码,告诉编译器自动引入如下命名空间而且作为默认命名空间,这个是绘制UI相关的程序集

System.Windows 
System.Windows.Automation 
System.Windows.Controls 
System.Windows.Controls.Primitives 
System.Windows.Data 
System.Windows.Documents 
System.Windows.Forms.Integration 
System.Windows.Ink 
System.Windows.Input 
System.Windows.Media 
System.Windows.Media.Animation 
System.Windows.Media.Effects 
System.Windows.Media.Imaging 
System.Windows.Media.Media3D 
System.Windows.Media.TextFormatting 
System.Windows.Navigation 
System.Windows.Shapes

 

这里还有一个x命名空间xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml",这个命名空间是对应XAML解析功能的,也就是和XAML编译器交流用的,比如x:Class="DeepXAML.MainWindow"就是告诉编译器将包含它的标签解析成类时,和那个类一起合并。

XAML文件的每个标签都会对应到具体的类,标签的属性大部分会对应类的属性。

我们编译后查看一下XAML文件被编译为MainWindow这个类.

image

抱歉!评论已关闭.