欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

RalativeSource Property理解-WPF

程序员文章站 2024-02-16 12:22:10
...

https://*.com/questions/84278/how-do-i-use-wpf-bindings-with-relativesource

If you want to bind to another property on the object(同一个Element):

{Binding Path=PathToProperty, RelativeSource={RelativeSource Self}}

If you want to get a property on an ancestor(Eelement可视化树父级):

{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}

RalativeSource Property理解-WPF

corner上的例子:https://www.c-sharpcorner.com/UploadFile/yougerthen/relativesources-in-wpf/

 

相关标签: WPF