Silverlight Tip of the Day #61 – How to Create a Tooltip
If you have a FrameworkElement such as an Image, Button, TextBlock, etc. you can add a tooltip to the element. Tooltips are usually small, boxed text that popup when a user hovers over the control. The purpose of the tooltip is to tell the user what the control does.
For example, let’s say we have a toolbar of flags that represent the language a user can select:
If a user did not recognize a flag they could hover over it and the tooltip would say what language the flag represents. For example:
To add a Tooltip to a FrameworkElement all you have to do is declare the property TooltipService.Tooltip. For Example:
<Image Source="images/france.png" ToolTipService.ToolTip="French">
A tooltip does not have to only be text, rather a tooltip can be any control you declare. For example, to make a tooltip an image you would declare it as:
<Image Source="images/france.png" Width="16" Height="16">
<ToolTipService.ToolTip>
<Image Source="images/france.png"></Image>
</ToolTipService.ToolTip>
</Image>
The result when hovering over the French flag would be the French flag at its original size:
Thank you,
--Mike Snow
Subscribe in a reader