wpf基础快速学习 一 xaml 基础知识学习

本文介绍了XAML的基础知识及语法,重点讲解了三种布局标签:Canvas、StackPanel与Grid的使用方法,并提供了实例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、xaml  基础知识 :xaml其实就是xml结构的脚本语言,与flex中的标签语言极其相识。

                                 主要用于Silverlight,WPF,Windows Phone以及Windows 8应用开发。

2、xaml语法          :

  1)命名空间声明

      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

  2) 标签

         .布局标签: Canvas(画布)、StackPanel(排列容器)与 Grid(表格)

                             Canvas       :画布 就像一张白纸一样想画什么就画什么。

                            StackPanel:是一个有规则排列的控件容器,在该里面的控件都会自动垂直或者水平有规律        

                                               的排列(如图按钮垂直排列)。

                                                    

                                               源码:

                                              <Window x:Class="firstApplicaton.Window1"                                                         
                                              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                                                                             
                                              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                                              

                                                Title="Window1" Height="300" Width="300">               

                                                <StackPanel>                               

                                                  <Button x:Name="button1" Content="按钮1" Width="80"/>                     

                                                  <Button x:Name="button2" Content="按钮2" Width="80" Height="21" />             

                                                     </StackPanel>                                           

                                               </Window>

                                Grid     :表格 整个界面就是一个表格的样式(图两行两列的表格)

               

                                                

                                               源码:

                                                 <Window x:Class="firstApplicaton.Window1"                                                        

                                                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                                                                
                                                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                                                        

                                                 Title="Window1" Height="300" Width="300">                                                       

                                               <Grid>                                                          

                                                <Grid.ColumnDefinitions>                                                              

                                                <ColumnDefinition Width="*"/>                                                              

                                                <ColumnDefinition Width="120"/>                                                             

                                                </Grid.ColumnDefinitions>                                                         

                                                <Grid.RowDefinitions>                                                             

                                               <RowDefinition Height="100"/>                                                              

                                            <RowDefinition Height="*"/>                                                             

                                            </Grid.RowDefinitions>        
                                                        

                                          <Button x:Name="button1" Content="按钮1" Width="80"  Height="20"
                                                          

                                           Grid.Column="0" Grid.Row="0"/>                                                         

                                        <Button x:Name="button2" Content="按钮2" Width="80" Height="20"
                                                          

                                          Grid.Column="1" Grid.Row="1" />                                                        

                                        </Grid>                                                   

                                     </Window>

           .常用标签 button 、label 、textBox 等等。

总体来说 xaml 跟html相似  但是比 html更好用。

转载于:https://www.cnblogs.com/happygod/archive/2013/01/29/2881513.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值