Adding tooltips to show additional information
Tooltips are used to show additional information about a specific control or a link when hovering your mouse over it. The FrameworkElement
class exposes a property named Tooltip
, which you can find on all the controls available in WPF.
In this recipe, we will learn how to work with the tooltips in WPF. We will also cover how to design a tooltip using other controls.
Getting ready
Open your Visual Studio IDE and create a new WPF application project called CH02.TooltipDemo
.
How to do it...
Open the MainWindow.xaml
page, and then follow these steps to add simple tooltips to the UI:
- First, replace the default
Grid
with aStackPanel
, and set itsOrientation
property toHorizontal
to have some horizontally stacked items. - Add three buttons to the
StackPanel
, and set theirToolTip
property. To add a show duration of the tooltip, set itsToolTipService.ShowDuration
attached property to a value in milliseconds. You can use the following XAML as a reference:
...