认识XAML

<Window x:Class="FirstDemo.WindowABC"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:c="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
        Title="MainWindow" Height="350" Width="525">
</Window>

1. xmlns = xml-namespace

2. xmlns:可选的映射前缀。没有前缀,称默认前缀,只能有一个,使用频率最多

3. 与.NET名称空间的语法不同,

例如:引用 System.Windows.Controls 名称空间的Button类

.NET 做法:

添加 PresentationFramework.dll -> using System.Windows.Controls

XAML 做法:

添加 PresentationFramework.dll -> xmlns:c ="clr-namespace:System.Windows.Controls; assembly=PresentationFramework"

根标签 的 xmlns:x 和 xmlns 名称空间(像网址),XAML的解析器的硬性编码,只要固定这些字符串,就会把一系列必要的程序集Assembly引用和命名空间引用进来

删除MainWindow.xaml.cs 后置代码,新建 WindowABC.cs

    public partial class WindowABC:Window
    {
        private Button btn;

        public WindowABC()
        {
            btn = new Button();
            btn.Width = 50;
            btn.Height = 50;
            btn.Content = "123123312";
            btn.Margin = new Thickness(0, 129, 0, 0);

            this.AddChild(btn);
        }
    }

<Window x:Class="FirstDemo.WindowABC" 和 注意 partial 机制

实现代码分离, 这就是XAML语言

posted @ 2012-09-27 21:02  Mr.Lin_♪  阅读(177)  评论(0)    收藏  举报