Search code examples
wpfbindingcollectionstooltipstackpanel

Binding collection of objects on a tooltip


Can someone tell me how to bind the tooltip of a StackPanel with its children?

Here's some code I used:

<StackPanel>
... (some UI like grid, textblock, border, ...)
<StackPanel.ToolTip>
 <ToolTip Placement="RelativePoint" Padding="0" HasDropShadow="False">
   <ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=StackPanel, AncestorLevel=3}, Path=Children}"
                 Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=StackPanel, AncestorLevel=3}, Path=ActualWidth}" 
                 Height="11">
   </ItemsControl>
  </ToolTip>
</StackPanel.ToolTip>
<StackPanel> 

I first tried with VisualBrush that was binded on a ToolTip, but this shows only the non-hidden controls, so when a child was hidden (invisible for the eye, not for the PC) in the StackPanel, then that child was also invisible in the ToolTip.

Also want to say that the binding with ActualWidth works. Now i have a tooltip that has the right measures, but there is no content in it (it's just a filled white space rectangle).

Someone please help me?? :)

FYI, what i want is the same like you bind on the Content property of a Textblock with his tooltip. The only difference is that i want to bind on a collection of objects instead of a string value.


Solution

  • The problem is probably caused by the fact the ToolTip is not part of the StackPanel's visual tree.

    Therefore the StackPanel is not an Ancestor of the ToolTip -> hence why the RelativeSource binding wont work.