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 Fi开发者_JAVA百科ndAncestor 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 MyControl using FindAncestor, then you can bind to properties of the DataContext like this:
<Label Content="{Binding DataContext.MyProperty, RelativeSource=…}" />
You can also just set an x:Name for MyControl and then the binding looks like:
<Label Content="{Binding DataContext.MyProperty, ElementName=myControl}" />
加载中,请稍侯......
精彩评论