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}
corner上的例子:https://www.c-sharpcorner.com/UploadFile/yougerthen/relativesources-in-wpf/