wpf 研习1-24小时自学wpf2

XAML,既然用户控件是一个大类,那么干脆对这个集合进行统一的编程模式,这就是xaml的原义。同时xaml的attribute programming是微软倡导式编程革命,enjoy this!

 

xmlns是xml形式的namespace,用于引入名字空间。见下例:

 

<Page xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”  

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

          <Button x:Name=”blueButton” Width=”100” Height=”40” Background=”Blue” Content=”Click Me” />

</Page>  

 

//code can make all-等效的c#程序片段

Button blueButton = new Button();
blueButton.Width = 100;
blueButton.Height = 40;
blueButton.Content = “Click Me”;
blueButton.Background = new SolidColorBrush(Colors.Blue);

  

xaml是微软描述wpf api的ui语言,是在普遍意义上将.net对象实例以直观形式进行序列化的语言(每个对象标签自动对应运行时的一个实例)它的“口号”是用一种简单形式写程序;

扩展名为.xaml;

可编译、可解释,编译后可嵌入c#例程代码(procedural code);

element对应object instance,attribute即properties of object;

根元素总是Page或Window标签;

 

控件 类库-System.Windows.Controls;

x:Name,对代码可访问的对象作唯一命名;

属性元素语法(property element syntax);

标签的Content属性可以是值类型,更可以是对象类型,系统自动进行类型转换;

<Button>
     <Button.Content>
          <Ellipse Width=”24” Height=”24” Fill=”Yellow” />
    </Button.Content>
</Button>

标记扩展(markup extensions),xaml中的重要概念,注意它的名值对的值不能使用双引号;

 



常用标记扩展/扩展标记如下:   

 

Common Markup Extensions in WPF 
NameDescription
BindingThe extension used for binding data.
StaticResourceThis is used for retrieving data from an application’s
resources. Static resources are not expected to change while
the application is running.
DynamicResourceSimilar to StaticResource, except that the data in the
resource might change during runtime.
x:Null Used for specifying a null value in XAML.
x:Type   This extension is used for supplying a System.Type object.
X:Array   This allows you to define an array of objects in XAML.

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值