Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WPF

WPF Grid: Showing Tooltip over Empty Space

5.00/5 (1 vote)
28 Dec 2010Apache 22.2K  
WPF Grid: Showing Tooltip over Empty Space

You can define a tooltip on a grid (or border), but it will show up only when the mouse hovers over space “occupied” by a grid item. Empty space will not generate the tooltip. E.g.

XML
<Grid ToolTip="Yo!">
   <Rectangle Fill="Yellow" Width="50" Height="50" HorizontalAlignment="Center" 
	VerticalAlignment="Center" />
</Grid>

The tooltip will show only when hovering over a small yellow rectangle in the middle, and not elsewhere in the grid. If you add <Rectangle /> to the grid, it won’t help. The rectangle by default gets null fill brush and sort of “does not count”. If you want to extend the tooltip on the whole grid, do this:

XML
<Grid ToolTip="Yo!">
   <Rectangle Fill="Transparent" />
   ... other items ...
</Grid>

This will ensure the tooltip is visible everywhere in the grid. However, if the grid is large, this looks somewhat weird. The tooltip appears once and does not follow the mouse. Thus, for large grids, it may be better to leave things as they are.

The same technique applies to a StackPanel and WrapPanel. Only space actually covered by controls like Label, Button, or Rectangle will have tooltip. Hovering over empty space will not yield a tooltip.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0