How do I use
| |||
|
up vote 71 down vote accepted | If you want to bind to another property on the object: {Binding Path=Pathtoproperty, relativeSource={relativeSource Self}} If you want to get a property on an ancestor: {Binding Path=Pathtoproperty, relativeSource={relativeSource AncestorType={x:Type typeOfAncestor}}} If you want to get a property on the templated parent (so you can do 2 way bindings in a ControlTemplate) {Binding Path=Pathtoproperty, relativeSource={relativeSource TemplatedParent}} or,shorter (this only works for OneWay bindings): {TemplateBinding Path=Pathtoproperty}
| ||||||
|
up vote 20 down vote | Binding relativeSource={ The default attribute of PrevIoUsData Allows you to bind the prevIoUs data item (not that control that contains the data item) in the List of data items being displayed. TemplatedParent Refers to the element to which the template (in which the data-bound element exists) is applIEd. This is similar to setting a TemplateBindingExtension and is only applicable if the Binding is within a template. Self Refers to the element on which you are setting the binding and allows you to bind one property of that element to another property on the same element. FindAncestor Refers to the ancestor in the parent chain of the data-bound element. You can use this to bind to an ancestor of a specific type or its subclasses. This is the mode you use if you want to specify AncestorType and/or AncestorLevel.
| |||
|
up vote 13 down vote | Here is the cheat-sheet that does help not being confused: http://www.nbdtech.com/Free/WpfBinding.pdf -aj
| |||
|
up vote 3 down vote | Don't forget TemplatedParent: <Binding relativeSource="{relativeSource TemplatedParent}"/> or {Binding relativeSource={relativeSource TemplatedParent}}
| ||
|
up vote 3 down vote | It's worthy of note that for those stumbling across this thinking of Silverlight: Silverlight offers a reduced subset only,of these commands
| ||
|
up vote 2 down vote | I just posted another solution for accessing the DataContext of a parent element in Silverlight that works for me. It uses
| ||
|
up vote 0 down vote | Here's a more visual explanation in the context of a MVVM architecture: />(http://www.rootsilver.com/2009/05/wpf-relativesource-ancestor-datacontext) |
以上是内存溢出为你收集整理的How do I use WPF bindings with RelativeSource?全部内容,希望文章能够帮你解决How do I use WPF bindings with RelativeSource?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)