Aren
Aren

Reputation: 55966

TemplatedParent - A clarification

Here's the Tree:

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 ?

Upvotes: 0

Views: 174

Answers (1)

Jay
Jay

Reputation: 57959

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}" />

Upvotes: 2

Related Questions