I'm trying to开发者_如何学Go understand RelativeSource binding but I can't find a definition for TemplatedParent. MSDN says:
"Gets a static value that is used to return a RelativeSource constructed for the TemplatedParent mode."
It doesn't appear in the index of "Windows Presentation Foundation Unleashed".
Simply, what is a TemplatedParent please?
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).
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.
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.
精彩评论