Showing posts with label tooltip. Show all posts
Showing posts with label tooltip. Show all posts

Monday, February 8, 2010

Tooltip for TextBlock in Silverlight (and any other Silverlight control)

I’ve always been used to “.ToolTip” to add a tool tip text to a control. Unfortunately not all Silverlight controls have such a property.

However, Silverlight does provide a class called “ToolTipService” so you can add a Tooltip to almost all Silverlight UI elements.

You can use the class both in the XAML

   1:  <TextBlock x:Name="txtblkNotification" Text="My Textblock">
   2:      <ToolTipService.ToolTip>
   3:          <ToolTip Content="My tool tip for the TextBlock"></ToolTip>
   4:      </ToolTipService.ToolTip>
   5:  </TextBlock>

Or directly in code

   1:  ToolTipService.SetToolTip(txtblkNotification, "My tool tip for the TextBlock");

I hope someone else finds this useful. (I sure did)