Click here to Skip to main content
15,902,198 members
Articles / Desktop Programming / WPF

WPF Grid: Showing Tooltip over Empty Space

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
28 Dec 2010Apache 21.9K   1   1
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.

This article was originally posted at http://www.ikriv.com/blog?p=778

License

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


Written By
Technical Lead Thomson Reuters
United States United States
Ivan is a hands-on software architect/technical lead working for Thomson Reuters in the New York City area. At present I am mostly building complex multi-threaded WPF application for the financial sector, but I am also interested in cloud computing, web development, mobile development, etc.

Please visit my web site: www.ikriv.com.

Comments and Discussions

 
SuggestionSimpler solution Pin
yossharel11-Jan-12 20:11
yossharel11-Jan-12 20:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.