Here’s the Tree:
- MyControl : BOUND(IContentMenuItem)
- ControlTemplate
- ContentPresenter : BOUND(Header, HeaderTemplate, HeaderTemplateSelector)
- DataTemplate (For Header)
- Label
- DataTemplate (For Header)
- ContentPresenter : BOUND(Header, HeaderTemplate, HeaderTemplateSelector)
- ControlTemplate
I Want to bind The Label @ the end of that tree to a property on the DataContext of MyControl
I can use FindAncestor to get the MyControl (Obviously) but how do I bind to it’s DataContext (of type IContentMenuItem)
Now for the Templated Parent Question
Will Binding to the TemplatedParent inside the DataTemplate in effect bind to The ContentPresenter, The ControlTemplate, or The MyControl ?
I think the answer to the TemplatedParent question is the
ContentPresenter— it is whatever the template is being applied to.If you can get
MyControlusingFindAncestor, then you can bind to properties of the DataContext like this:You can also just set an
x:NameforMyControland then the binding looks like: