How do I use
|
|||
|
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} |
|||||||||
|
Binding RelativeSource={ The default attribute of
|
|||
Here is the cheat-sheet that does help not being confused: http://www.nbdtech.com/Free/WpfBinding.pdf -aj |
|||||
|
Don't forget TemplatedParent: <Binding RelativeSource="{RelativeSource TemplatedParent}"/> or {Binding RelativeSource={RelativeSource TemplatedParent}} |
|||
|
It's worthy of note that for those stumbling across this thinking of Silverlight: Silverlight offers a reduced subset only,of these commands |
|||
|
I just posted another solution for accessing the DataContext of a parent element in Silverlight that works for me. It uses |
|||
|
Here's a more visual explanation in the context of a MVVM architecture: (http://www.rootsilver.com/2009/05/wpf-relativesource-ancestor-datacontext) |
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。