I am styling a TreeViewItem. The item has a content presenter that I wish to have a tooltip appear:
<ContentPresenter x:Name="PART_Header"
Cursor="Hand"
Grid.Column="1"
ContentSource="Header"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
<ContentPresenter.ToolTip>
<ToolTip
Placement="RelativePoint"
VerticalOffset="-2"
HasDropShadow="False"
BorderBrush="#767676"
Background="#FFF"
Padding="0,1,0,1"
VerticalAlignment="Center"
Content="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ContentPresenter}}, Path=Content}"/>
</ContentPresenter.ToolTip>
</ContentPresenter>
This is effectively part of a larger setter that sets the item’s control template. However, I cannot seem to get the Tooltip’s content binded to the content presenter’s content. It keeps appearing blank (a tiny black box). I am new to binding and WPF, so please excuse.
ToolTips and other popups exist outside the main visual tree and so can’t use RelativeSource to get to parents. Try instead using the ToolTip’s PlacementTarget property to get to its parent ContentPresenter: