I have an attached property that looks like this:
<Button Styles:ToolTip.Title="The Title"/>
I setup a style to access show it like this:
<TextBlock Text="{Binding Path=(Styles:ToolTip.Title),
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}"/>
The problem with this binding is that it can ONLY work when my property is on a Button.
I am making a custom ToolTip feature, so I want it to work on any control that would normally show a tooltip.
Normally I would just bind to TemplatedParent. But that is the ContentPresenter.
How can I get a source pointing back to the object that has the attached property on it (and not reference it statically in code)?
Here is my full style in case it is needed.
UPDATE:
This was what did it. I changed my RegisterAttached method’s last parameter to be this:
new FrameworkPropertyMetadata(default(string),
FrameworkPropertyMetadataOptions.Inherits)
You could try making the property an inherited dependency property. Then setting the value on the parent Button would cause the child TextBlock inherit the value