WPF快速入门1-XAML(window、Page、Application、属性、附加属性、特殊字符、保留空白、事件)

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);
        }


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tiz198183

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值