Thursday, August 26, 2010

Creating Fancy Tooltips in WPF

Each control in WPF has a Tooltip property that can be accessed through XAML or code behind. The Tooltip property can host any kind of controls such as a rectangle, text block, or a panel. In other words, we can display another window with any number of controls as a tooltip of a control.
The following code creates a simple tooltip for a button control.
       <Button Width="100" Height="30">Click Me
                <ToolTip>This is a tooltip test for a button control. You
                    can click me if you want but I will do nothing for you.
The output looks like Figure 1.
Figure 1. A simple Tooltip
As I said earlier, a Tooltip can host any number of controls. For example, in the below code, a button tooltip hosts a StackPanel with two children StackPanels. First StackPanel hosts an image and a text block and second StackPanel hosts a larger textblock. The output looks like Figure 2, which is a fancy tooltip.

See full details: