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:FactoryMethod
x: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) > 在属性( ...
随机推荐
- Oracle 修改oracle数据库名
Oracle 修改oracle数据库名 by:授客 QQ:1033553122 1.确保你有个可用于数据库恢复的,完整的数据库备份 2.确保数据库处于mount,非open状态,并且在加载前先以imm ...
- Python 列表(List)操作方法详解
Python 列表(List)操作方法详解 这篇文章主要介绍了Python中列表(List)的详解操作方法,包含创建.访问.更新.删除.其它操作等,需要的朋友可以参考下 列表是Python中最基本 ...
- 解决 ModuleNotFoundError: No module named 'pip'
安装其它python包时,提示说 pip 10.0.1可用,就更新了一下,但是 更新过程中出现了错误,如图所示 因为这个错误导致 pip找不到, 可以首先执行 python -m ensurepip ...
- Python数据类型之list和tuple
list是一种有序的集合,可以随时添加和删除其中的元素. 用len()函数可以获得list元素的个数. 用索引来访问list中每一个位置的元素,索引是从0开始的.如果要取最后一个元素,除了计算索引位置 ...
- LINQ学习:Select的用法
转载于:http://www.cnblogs.com/ForEvErNoME/archive/2012/07/25/2606659.html 说明:在查询表达式中,select 子句可以指定将在执行查 ...
- 在IE中,JS方法名和input的name重名时,调用该方法无效
在IE中,JS方法名和input的name重名时,调用该方法无效.提示:网页错误详细信息 用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1 ...
- 解决:Determining IP Information for eth0...问题
环境:Centos 6.2 VMWare Workstation 7.1.2 故障现象: 在虚拟机中启动Centos,在启动页面中停留在Determining IP Information ...
- python模拟自动登录网站(urllib2)
不登录打开网页: import urllib2 request = urllib2.Request('http://www.baidu.com') response = urllib2.urlopen ...
- 【Vue.js学习】生命周期及数据绑定
一.生命后期 官网的图片说明: Vue的生命周期总结 var app = new Vue({ el:"#app", beforeCreate: function(){ consol ...
- Django商城项目笔记No.16用户部分-用户中心收货地址
首先完成省市区三级联动 新建areas应用 python ../../manage.py startapp areas 模型类代码 class Area(models.Model): "&q ...