WPF快速入门1——WPF基本树形结构解析

首先,新建一个WPF应用程序:
在这里插入图片描述

可以看到.xmal文件中的内容为:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        
    </Grid>
</Window>

可以看到xmal的结构就是一种树形结构,有根节点、分支节点、叶子节点等等组成。
可以看到目前的最基本形式是根节点<Window> 下嵌套着<Grid>:

<Window>
    <Grid>
        
    </Grid>
</Window>

xmal是一种声明性语言,每个标签即代表了一个对象,各个对象之间要么是并列、要么是嵌套。而标签可以是上面<Grid>那种空标签也可以是<Window> 那种包含了各种特征的非空标签。
其中,标签的特征可以分为:Attribute、Property两类。
Property表示标签的属性,一般用来表示对象状态的量就被抽象为Property;
Attribute表示标签的特征,一般只与语言层面的东西相关。

可以看到上面的<Window>标签下:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">

Title、Height、Width这些就是Window对象的Property;
前面的

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

则是在声明命名空间(xmlns即xml namespace);
xmlns特征的语法格式为:

xmlns[:可选的映射前缀]="命名空间"

最上面的:

x:Class="WpfApplication1.MainWindow"

是在使用名为Class的Attribute。

然后增加一些控件内容:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="279.6" Width="491.4">
    <StackPanel Background="LightBlue">
        <TextBox x:Name="textBox" Height="50" Margin="4" Background="LightCoral"/>
        <TextBox x:Name="tex2Box" Height="50" Margin="4" Background="AliceBlue"/>
        <StackPanel Orientation="Horizontal">
            <TextBox x:Name="textBox1" Width="150" Height="50" Margin="5" Background="LightGreen"/>
            <TextBox x:Name="textBox2" Width="150" Height="50" Margin="5" Background="Beige"/>
            <TextBox x:Name="textBox3" Width="150" Height="50" Margin="5" Background="LightPink"/>
        </StackPanel>
        <Button x:Name="button1" Margin="5" Width="200" Height="50">
            <TextBlock Text="Button"/>
        </Button>

    </StackPanel>

</Window>

窗口效果如图:

在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值