码迷,mamicode.com
首页 > Windows程序 > 详细

WPF Binding源

时间:2017-10-30 19:54:10      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:previous   ref   http   相对   ati   log   block   red   string   

Bingding的源:

有三个属性用来设置源:ElementName(string)、Source(Object) 和 RelativeSource(RelativeSource)。注:这三个只能指定一个,否则异常。
ElementName: 源为一个元素(Element),这里用的是此元素中设置的Name属性。
Source:以object作为源。<TextBlock Text="{Binding Source={StaticResource myDataSource}, Path=PersonName}"/>
RelativeSource: 源相对于绑定目标的位置。
                        源是元素本身:{Binding RelativeSource={RelativeSource Self}}
                        源是Tempalte中元素的Parent:{Binding RelativeSource={RelativeSource TemplatedParent}}
                        源是绑定以collection形式的前一个数据:{Binding RelativeSource={RelativeSource PreviousData}},MSDN上关于PreviousData的说明并不多,这里有一篇文章可以参考
                        以上三项为RelativeSource中的Static值,使用这些值可以减少内存开销
                        源是Ancestor(可能比parent还高):{Binding RelativeSource={RelativeSource FindAncestor,
                                                                     AncestorLevel=n, AncestorType={x:Type desiredType}}}

WPF Binding源

标签:previous   ref   http   相对   ati   log   block   red   string   

原文地址:http://www.cnblogs.com/cuiguangzhen/p/7755687.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!