WPF binding 参考
Introduction
This is an article on WPF Binding Cheat Sheet. Some of the Binding won't work for Silverlight 3.
Basic Binding |
|
| {Binding} | Bind to current DataContext. |
| {Binding Name} | Bind to the "Name" proeprty of the current DataContext. |
| {Bindind Name.Length} | Bind to the Length property of the object in the Name property of the current DataContext |
| {Binding ElementName=SomeTextBox, Path=Text} | Bind to the "Text" property of the element XAML element with name="SomeTextBox" or x:Name="SomeTextBox". |
XML Binding |
|
| {Binding Source={StaticResource BooksData} XPath=/books/book} | Bind the result of XPath query "/books/book" from the XML in the XmlDataProvider in a parent's "Resources" elememt with x:Key="BooksData". |
| {Binding XPath=@name} | Bind to the result of an XPath query run on the XML node in the DataContext (for example in an ItemControl's DataTemplate when the ItemsControl.ItemsSource is bound to an XML data source). |
Relative Source Binding |
|
| {Binding RelativeSource={RelativeSource Self}} | Bind to the target element. |
| {Binding RelativeSource={RelativeSource Self}, Path=Name} | Bind to the "Name" property of the target element. |
| {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=Title} | Bind to the title of the parent window. |
| {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}, AncestorLevel=2}, Path=Name} | Bind the the name of the 2nd parent of type ItemsControl. |
| {Binding RelativeSource={RelativeSource TemplatedParent}, Path=Name} | Inside a control template, bind to the name property of the element the template is applied to. |
| {TemplateBinding Name} | Shortcut for the previous example. |
Collection Current Item Binding |
|
| {Binding /} | Bind to the current item in the DataContext (when DataContext is a collection) |
| {Binding AllItems/} | Bind to the current item in the "AllItems" property of the DataContext |
| {Binding AllItems/Name} | Bind to the "Name" property of the current item in the "AllItems" property of the DataContext |
Alphabetical list of all Binding's properties
Property |
Description |
| BindingGroupName (3.5sp1) | The name of the BindingGroup to which this binding belongs. A BindingGroup is used to validate multiple bindings together (for example when multiple changes should be submitted all at once). |
| BindsDirectlyToSource | When using a DataSourceProvider derived class (for example a ObjectDataProvider) setting this property to true will bind to the data source provider object itself, leaving it false will bind to the data contained in the data source. |
| Converter | The converter to use, usually you create the converter in a parent element's Resources element and reference it using a {StaticResource name) or create the converter as a static field and reference it with {x:Static ns:class.field} |
| ConverterCulture | The culture passed to the converter. |
| ConverterParameter | The parameter passed to the converter |
| ElementName | Element name, when binding to an element in the same XAML scope. Can't be used if RelativeSource or Source is set. |
| FallbackValue | Value to use when the Binding encounters an error |
| IsAsync | Use when the property's get accessor takes a long time, to avoid blocking the UI thread, While waiting for the value to arrive, the binding reports the FallbackValue. |
| Mode | Direction of binding, possible options:
|
| NotifyOnSourceUpdated | Raise the SourceUpdated event when a value is transferred from the binding target to the binding source. |
| NotifyOnTargetUpdated | Raise the TargetUpdated event when a value is transferred from the binding source to the binding target. |
| NotifyOnValidationError | Raise the Error attached event on the bound object. |
| Path | Source property. |
| RelativeSource | Binding source relative to the target, possible options:
|
| Source | Object to use as the binding source. Can't be used if ElementName or RelativeSource is set. |
| StringFormat (3.5sp1) | Format string to use when converting the bound value to a string. Works only if the target property is of type string. |
| TargetNullValue (3.5sp1) | Value to use when the bound value is null. |
| UpdateSourceExceptionFilter | Custom logic for handling exceptions that the binding engine encounters. Only if you add an ExceptionValidationRule to ValidationRules or set ValidatesOnExceptions |
| UpdateSourceTrigger | Timing of binding source updates, possible options:
|
| ValidatesOnDataErrors (3.5sp1) | Use IDataErrorInfo when validating. |
| ValidatesOnExceptions (3.5sp1) | Treat exceptions as validation failures. |
| ValidationRules | Collection of rules that check the validity of the user input. |
| XPath | XPath query that returns the value on the XML binding source to use. Top |
WPF binding 参考的更多相关文章
- WPF入门教程系列(二) 深入剖析WPF Binding的使用方法
WPF入门教程系列(二) 深入剖析WPF Binding的使用方法 同一个对象(特指System.Windows.DependencyObject的子类)的同一种属性(特指DependencyProp ...
- WPF Binding值转换器ValueConverter使用简介(二)-IMultiValueConverter
注: 需要继承IMultiValueConverter接口,接口使用和IValueConverter逻辑相同. 一.MultiBinding+Converter 多值绑定及多值转换实例 当纵向流量大于 ...
- WPF Binding值转换器ValueConverter使用简介(一)
WPF.Silverlight及Windows Phone程序开发中往往需要将绑定的数据进行特定转换,比如DateTime类型的时间转换为yyyyMMdd的日期,再如有一个值是根据另外多组值的不同而异 ...
- WPF Binding
winform有binding, WPF也有binding,区别在哪呢?这里暂时不提.以前也检查接触WPF binding, 但为什么过段时间就忘记了呢? 可能主要原因自己的知识体系不够完善吧,下面我 ...
- WPF Binding Mode,UpdateSourceTrigger
WPF 绑定模式(mode) 枚举值有5个1:OneWay(源变就更新目标属性)2:TwoWay(源变就更新目标并且目标变就更新源)3:OneTime(只根据源来设置目标,以后都不会变)4:OneWa ...
- WPF Binding ElementName方式无效的解决方法--x:Reference绑定
原文:WPF Binding ElementName方式无效的解决方法--x:Reference绑定 需求: 背景:Grid的有一个TextBlock name:T1和一个ListBox,ListBo ...
- WPF Binding学习(四) 绑定各种数据源
转自:http://blog.csdn.net/lisenyang/article/details/18312199 1.集合作为数据源 首先我们先创建一个模型类 public class Stude ...
- UpdateSourceTrigger Property in WPF Binding
介绍 这篇文章我将介绍在WPF和Silverlight中更新绑定源的概念.正如您所知道的,当我们用TwoWay的模式绑定时,任何在目标控件上发生的变化都会影响绑定源的值. 请注意只是在用TwoWay绑 ...
- .NET: WPF Binding对数据的校验和转换以及多路Binding
一.校验 一般需要对target上的值进行校验. xaml: <Window x:Class="WpfApplication1.MainWindow" xmlns=" ...
随机推荐
- 理解 .NET Platform Standard
相关博文:ASP.NET 5 Target framework dnx451 and dnxcore50 .NET Platform Standard:https://github.com/dotne ...
- 【基于WPF+OneNote+Oracle的中文图片识别系统阶段总结】之篇一:WPF常用知识以及本项目设计总结
篇一:WPF常用知识以及本项目设计总结:http://www.cnblogs.com/baiboy/p/wpf.html 篇二:基于OneNote难点突破和批量识别:http://www.cnblog ...
- 代码的坏味道(21)——中间人(Middle Man)
坏味道--中间人(Middle Man) 特征 如果一个类的作用仅仅是指向另一个类的委托,为什么要存在呢? 问题原因 对象的基本特征之一就是封装:对外部世界隐藏其内部细节.封装往往伴随委托.但是人们可 ...
- 从源码浅析MVC的MvcRouteHandler、MvcHandler和MvcHttpHandler
熟悉WebForm开发的朋友一定都知道,Page类必须实现一个接口,就是IHttpHandler.HttpHandler是一个HTTP请求的真正处理中心,在HttpHandler容器中,ASP.NET ...
- 如何理解javaSript中函数的参数是按值传递
本文是我基于红宝书<Javascript高级程序设计>中的第四章,4.1.3传递参数小节P70,进一步理解javaSript中函数的参数,当传递的参数是对象时的传递方式. (结合资料的个人 ...
- Zephyr OS 简介
最新发布的开源 Zephyr Project™(Zephyr 项目)是一款小型且可伸缩的实时操作系统,尤其适用于资源受限的系统,可支持多种架构:该系统高度开源,对于开发人员社区完全开放,开发人员可根据 ...
- .NET面试题系列[7] - 委托与事件
委托和事件 委托在C#中具有无比重要的地位. C#中的委托可以说俯拾即是,从LINQ中的lambda表达式到(包括但不限于)winform,wpf中的各种事件都有着委托的身影.C#中如果没有了事件,那 ...
- 《深入理解Java虚拟机》调优案例分析与实战
上节学习回顾 在上一节当中,主要学习了Sun JDK的一些命令行和可视化性能监控工具的具体使用,但性能分析的重点还是在解决问题的思路上面,没有好的思路,再好的工具也无补于事. 本节学习重点 在书本上本 ...
- 基于Kubernetes在AWS上部署Kafka时遇到的一些问题
作者:Jack47 转载请保留作者和原文出处 欢迎关注我的微信公众账号程序员杰克,两边的文章会同步,也可以添加我的RSS订阅源. 交代一下背景:我们的后台系统是一套使用Kafka消息队列的数据处理管线 ...
- WCF : 如何将NetTcpBinding寄宿在IIS7上
摘要 : 从IIS 7 开始, IIS增加了对非HTTP协议的支持. 因此, 自IIS 7之后, 可以将NetTcpBinding等非HTTP协议的Bindings直接寄宿在IIS上面. 本文将介绍如 ...