XAML扩展应用标记语言,构建WPF的用户界面。
一、XAML标准
所有都会映射类的实例
1、窗体
<!--Window元素-->
<Window x:Class="WpfApplication1.Window4"
<!--x:Class 告诉XAML编译器将XAML编译器编译的结果和后台编译结果的哪一个类进行合并-->
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
<!--xmlns="命名空间" 所有WPF的类(为默认命名空间,元素会自动应用这个命名空间)-->
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
<!--xmlns:x="命名空间" xaml命名空间,别名为X,可以用<X:...>别名访问-->
Title="Window4" Height="300" Width="300">
<!--Grid元素-->
<Grid>
</Grid>
</Window>
2、页
<!--Page元素-->
<Page x:Class="WpfApplication1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="Page1">
<Grid>
</Grid>
</Page>
3、Application
<!--Application元素-->
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window3.xaml">
<!--StartupUri启动地址-->
<Application.Resources>
</Application.Resources>
</Application>
二、XAML中的属性
1、简单属性
<Grid Name="grid1"></Grid>
2、属性元素
<Grid>
<Grid.Name>grid1</Grid.Name>
</Grid>
3、附加属性
使用另了控件的属性
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button Content="Button" Name="button1" Grid.Row="0"/>
<!--Grid.Row="0" 附加属性-->
</Grid>
4、特殊字符
实例:<>
<Button Content="<Button>" Name="button1" Grid.Row="0"/>
5、空白
<TextBox Height="23" Name="textBox1" Width="120" xml:space="preserve">11" "22</TextBox>
<!--xml:space="preserve" 保留空格-->
三、XAML中的事件
private void Window_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show(textBox1.Text);
}