What's new in XAML of .NET 4.0( .NET 4.0中XAML的新功能 )
原文 What's new in XAML of .NET 4.0
What's new in XAML of .NET 4.0
Easy Object References with {x:Reference} 使用{x:Reference}轻松引用对象
Generics in XAML with x:TypeArguments XAML中的泛型 x:TypeArguments
Support for Arbitrary Dictionary Keys 支持任意字典键
Use of Non-Default Constructors with x:Arguments 使用非默认构造函数 x:Arguments
Use of Static Factory Methods with x:FactoryMethod 使用静态工厂方法 x:FactoryMethod
With .NET 4.0 Microsoft will bring up a improved version of XAML. This arcitle shows you the language enhancements they made.
使用.NET 4.0,Microsoft将推出XAML的改进版本。这个arcitle向您展示了他们所做的语言增强。
Easy Object References with {x:Reference}
If you want to create an object reference today you need to do a
databinding and declare the source with an ElementName. In XAML 2009 you
can use the new {x:Reference} markup extension
<!-- XAML 2006 -->
<Label Target="{Binding ElementName=firstName}">FirstName</Label>
<TextBox x:Name="firstName" />
<!-- XAML 2009 -->
<Label Target="{x:Reference firstName}">FirstName</Label>
<TextBox x:Name="firstName" />
Built-in Types
If you want to add objects of simple types like string or double to a resource dictionary today you need to map the needed clr-namespaces to an XML namespaces. In XAML 2009 we a lot of simple types that are included in the XAML language.
<!-- XAML 2006 -->
<sys:String xmlns:sys="clr-namespace:System;assembly=mscorlib >Test</sys:String>
<!-- XAML 2009 -->
<x:String>Test</x:String>
The following types are included into the XAML language:
<x:Object/><x:Boolean/><x:Char/><x:String/><x:Decimal/><x:Single/><x:Double/><x:Int16/><x:Int32/><x:Int64/><x:TimeSpan/><x:Uri/><x:Byte/><x:Array/><x:List/><x:Dictionary/>
Generics in XAML with x:TypeArguments
If you want to use an ObservableCollection<Employee> in XAML you need to create a type that derives from ObservableCollection because you cannot declare it in XAML. With XAML 2009 you can use the x:TypeArguments attribute to define the type of a generic type.
<!-- XAML 2006 -->
class EmployeeCollection : ObservableCollection<Employee>
{
}
<l:EmployeeCollection>
<l:Employee FirstName="John" Name="Doe" />
<l:Employee FirstName="Tim" Name="Smith" />
</lEmployeeCollection>
<!-- XAML 2009 -->
<ObservableCollection x:TypeArguments="Employee">
<l:Employee FirstName="John" Name="Doe" />
<l:Employee FirstName="Tim" Name="Smith" />
</ObservableCollection />
Support for Arbitrary Dictionary Keys
In XAML 2006 all explicit x:Key value were threated as strings. In XAML 2009 you can define any type of key you like by writing the key in ElementSyntax.
<!-- XAML 2006 -->
<StreamGeometry x:Key="CheckGeometry">M 0 0 L 12 8 l 9 12 z</StreamGeometry>
<!-- XAML 2009 -->
<StreamGeometry>M 0 0 L 12 8 l 9 12 z
<x:Key><x:Double>10.0</x:Double></x:Key>
</StreamGeometry>
Use of Non-Default Constructors with x:Arguments
In XAML 2006 objects must have a public default constructor to use them. In XAML 2009 you can pass constructor arguments by using the x:Arguments syntax.
<!-- XAML 2006 -->
<DateTime>00:00:00.0000100</DateTime>
<!-- XAML 2009 -->
<DateTime>
<x:Arguments>
<x:Int64>100</x:Int64>
</x:Arguments>
</DateTime>
Use of Static Factory Methods with x:FactoryMethod
When you have a type that has no public constructor but a static factory method you had to create that type in code in XAML 2006. With XAML 2009 you can use the x:FactoryMethodx:Arguments attribute to pass the argument values.
<!-- XAML 2006 -->
Guid id = Guid.NewGuid();
<!-- XAML 2009 -->
<Guid x:FactoryMethod="Guid.NewGuid" />
What's new in XAML of .NET 4.0( .NET 4.0中XAML的新功能 )的更多相关文章
- 捕捉WPF应用程序中XAML代码解析异常
原文:捕捉WPF应用程序中XAML代码解析异常 由于WPF应用程序中XAML代码在很多时候是运行时加载处理的.比如DynamicResource,但是在编译或者运行的过程中,编写的XAML代码很可能有 ...
- 关于 WP 开发中.xaml 与.xaml.cs 的关系
今天我们先来看一下在WP8.1开发中最长见到的几个文件之间的关系.比较论证,在看这个问题之前我们简单看看.NET平台其他两个不同的框架: Windows Forms 先看看Window Forms中的 ...
- WP 开发中.xaml 与.xaml.cs
关于 WP 开发中.xaml 与.xaml.cs 的关系 今天我们先来看一下在WP8.1开发中最长见到的几个文件之间的关系.比较论证,在看这个问题之前我们简单看看.NET平台其他两个不同的框架: ...
- wpf中xaml的类型转换器与标记扩展
原文:wpf中xaml的类型转换器与标记扩展 这篇来讲wpf控件属性的类型转换器 类型转换器 类型转换器在asp.net控件中已经有使用过了,由于wpf的界面是可以由xaml组成的,所以标签的便利也需 ...
- 整理:WPF中Xaml中绑定枚举的写法
原文:整理:WPF中Xaml中绑定枚举的写法 目的:在Combobox.ListBox中直接绑定枚举对象的方式,比如:直接绑定字体类型.所有颜色等枚举类型非常方便 一.首先用ObjectDataPro ...
- 【随记】WPF中xaml输入中文乱码问题解决
在Visual Studio中开发WPF应用程序时,在XMAL文档编写界面输入中文时变为乱码.可能的原因之一是VS中安装了VAssistX插件,导致编码冲突,使中文输入乱码.解决方法是在VAssist ...
- WPF中XAML的触发器的属性,事件 都有那些?以及如何寻找
在编写XAML的触发器时,会有属性,事件. 那么这些都是哪里来的呢? 属性,是附加属性或者依赖属性 事件,那就是事件. 如何寻找呢? 很简单,在想要使用的触发器的对象上(也就是有光标的时候)按下F12 ...
- WPF中Xaml编译正常而Designer Time时出错的解决办法
开发wpf时我们经常遇到一个xaml文件在设计时显示解析错误(比如在:VS或者Blend)而编译正常运行正常. 原因是:xaml的在Debug版本下必须为anyCPU. 解决办法: 1.打开工程文件x ...
- WPF中XAML转义字符
字符 转义字符 备注 & (ampersand) & 这个没什么特别的,几乎所有的地方都需要使用转义字符 > (greater-than character) > 在属性( ...
随机推荐
- Problem4-Project Euler
Largest palindrome product A palindromic number reads the same both ways. The largest palindrome m ...
- CSS揭秘(二)背景与边框
Chapter2 背景与边框 1. 半透明边框 基础:了解 RGBA & HSLA 颜色(色调 0~360.饱和度.亮度 (0%黑色~100%白色).透明度) 默认情况下,背景在边框的下层,容 ...
- zabbix agent 3.4 安装指南
从官方网站www.zabbix.com 下载zabbix agent安装包.目前最新版本是4.0 LTS release. 在需要监控的服务器上安装zabbix agent. 先解压安装包. 配置 c ...
- linux正则表达式(基础正则表达式+扩展正则表达式)
正则表达式应用非常广泛,例如:php,Python,java等,但在linux中最常用的正则表达式的命令就是grep(egrep),sed,awk等,换句话 说linux三剑客要想能工作的更高效,就一 ...
- 批处理之windows更改网卡IP地址
新建文本文档,更改后缀为“.bat”,写入以下代码: netsh interface ip set address name="本地连接" source=static 192.16 ...
- 乘风破浪:LeetCode真题_035_Search Insert Position
乘风破浪:LeetCode真题_035_Search Insert Position 一.前言 这次的问题比较简单,也没有限制时间复杂度,但是要注意一些细节上的问题. 二.Search Insert ...
- hyper-v NAT网络
宿主机:windows 2008 R2 企业版 hyper-V配置静态IP地址 https://jingyan.baidu.com/article/925f8cb8ae1ee2c0dde05632.h ...
- Mysql学习第二天
Mysql语句执行 用户登录与管理 mysql -uroot -p -hlocalhost test # 指定登录test数据库 mysql -uroot -p -hlocalhost company ...
- linux命令2—常见linux命令
1.进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi +n filename :打开文件,并将光标置于第n行首 vi + filename :打开文件,并将光标置于 ...
- xpath获取带注释的text
from lxml import etree html_str = """<div id="box1">this from blog.cs ...