且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无废话WPF系列1:XAML分析

更新时间:2022-09-11 11:23:27

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

无废话WPF系列1:XAML分析

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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这个类.

无废话WPF系列1:XAML分析

本文转自敏捷的水博客园博客,原文链接http://www.cnblogs.com/cnblogsfans/archive/2011/02/19/1958573.html如需转载请自行联系原作者


王德水