WPF ToolTip Content binding

Did you know that content of a ToolTip is neither a part of visual nor logical tree? I didn't so I was trying to bind a ToolTip.Content using ElementName. And it didn't work:

<TextBlock Name="box" Text="Text to place inside tooltip" />
<Button Content="Can't Bind">
<ToolTip Content="{Binding ElementName=box,

Button has a tiny empty tooltip:


This code seemed perfectly fine for me so it took me a lot of time to google the answer. The only way to make that binding happen doesn't look nice but it's a simple trick: bind to a Grid DataContext. Seriously :-)

<Grid DataContext="{Binding ElementName=box, Path=Text}" >
<Button Content="Tricky Evil Solution ;-)"/>
<ToolTip Content="{Binding Path=PlacementTarget.DataContext,
RelativeSource={RelativeSource Self}}"

And now the tooltip looks ok:


My original problem was binding a ToolTip.Content to validation errors and I really needed a way to do that. Please tell me if you know a better one :-)
Code can be found here.


Update: This works too! :-)

<Button ToolTip="{Binding ElementName=box, Path=Text}"  />

1 Comment

  • Thanks Frank, great source about validation. One thing though: I recommend using Validation.Errors).CurrentItem instead of (Validation.Errors)[0].ErrorContent as described here


    Now I know what to do with that tooltip :-)

Comments have been disabled for this content.