Prev | Current Page 376 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"


Tooltips
WPF has a flexible model for tooltips (those infamous yellow boxes that pop up when you
hover over something interesting). Because tooltips in WPF are content controls, you can
CHAPTER 7 n CLASSIC CONTROLS 198
place virtually anything inside a tooltip. You can also tweak various timing settings to control
how quickly tooltips appear and disappear.
The easiest way to show a tooltip doesn??™t involve using the ToolTip class directly. Instead,
you simply set the ToolTip property of your element. The ToolTip property is defined in the
FrameworkElement class, so it??™s available on anything you??™ll place in a WPF window.
For example, here??™s a button that has a basic tooltip:

When you hover over this button, the text ???This is my tooltip??? appears in the familiar
yellow box.
If you want to supply more ambitious tooltip content, such as a combination of nested
elements, you need to break the ToolTip property out into a separate element. Here??™s an
example that sets the ToolTip property of a button using more complex nested content: