In WPF, what is a TemplatedParent?

前端 未结 3 2070
小鲜肉
小鲜肉 2020-12-29 20:48

I\'m trying to understand RelativeSource binding but I can\'t find a definition for TemplatedParent. MSDN says:

\"Gets a static value that is used to

相关标签:
3条回答
  • 2020-12-29 21:28

    Notice:

    TemplatedParent means Parent is Templated. Templated is passive voice in English. In other words, the parent element is applied with a Template. So in the template you can binding the parent's property easily.

    0 讨论(0)
  • 2020-12-29 21:30

    In WPF, a template is what it uses to construct the tree of a type. WPF essentially makes a copy of the template when a new object of that type is created.

    As a result, inside the template, if you want to refer to the new object, you use TemplatedParent for quick access. Otherwise, you'll have to use RelativeSource to walk the tree upwards to find the parent object.

    0 讨论(0)
  • 2020-12-29 21:43

    TemplatedParent refers to the Control instance that the template is being applied to. You can use TemplatedParent to bind to properties declared on that object (and its base classes).

    0 讨论(0)
提交回复
热议问题