How do I use Relativesource
with WPF bindings and what are the different use-cases?
大佬教程收集整理的这篇文章主要介绍了How do I use WPF bindings with RelativeSource?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
|
|||
|
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} |
||||||||||||||||||||||||||||||||||||||||||
|
It turns out,as I revisit this,that the object in question is the object upon which the binding is being applied. I tried using <Button Tag="{Binding Relativesource={Relativesource Self}}" /> and looking in the debugger. The Tag property contained the button itself. –
Drew Noakes
@H_290_447@mar 3 '09 at 9:31
|
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 |
||||||||||||||||||||||||||||
@H_133_772@ |
Don't forget TemplatedParent: <Binding Relativesource=@H_265_801@"{Relativesource TemplatedParent}"/> or {Binding Relativesource={Relativesource TemplatedParent}} |
|||
|
It's worthy of note that for those stuR_768_11845@bling 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 |
|||
@H_673_1075@
|
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?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。