Did it annoy you, ever, that the ToolTip class was so darned limited in the .NET Framework? For cryin' out loud - it used to be "Sealed". I have always maintained that making that class Sealed was not the right choice. And then to pour salt over my wounds, Microsoft introduced "Super Tooltips" in Office 2007. Super ToolTips that blogs.msdn.com brags so shamelessly about. A bit like, we can do this, but you can't. Nyah Nyah Nyah Nyah Nyah !!
Well, no more. WPF will let you create, your very own Super ToolTips. And it's pretty easy too .. .
First of all, what is a Super ToolTip? While a regular ToolTip looks like a yellow box with some text in it, a Super ToolTip can look like this -
As is evident from the above, a Super ToolTip conveys SO MUCH more information. Not only that, Super ToolTips can also offer interactivity to the End User by putting things such as ComboBoxes, and CheckBoxes - much like that annoying
floater, I mean Floatie that Word 2007 has -
Tip: If you find that annoying, you can turn it off by going to the Word Options -> Turn off "Show Mini Toolbar on Selection".
Suggestion: I wish Visual Studio Orcas makes use of Super ToolTips.
Getting to the point, how can you have fancy tooltips like those in your own programs? With .NET 2.x and before - you can't. With WPF, you can.
Say, I wish to create a button, whose ToolTip will be that fancy Super ToolTip. First, how can I create a button with a Tool Tip? You can, like this -
Button btn = new Button();
btn.Content = "My Button";
btn.Margin = new Thickness(48);
ToolTip tip = new ToolTip();
// Super ToolTip code comes here
Content = btn;
Now, how can we make this ToolTip "Super"? Well, like all WPF UIElements, ToolTip has a property called "Content". The cool thing about Content is, you can stuff in pretty much anything in there. A CheckBox, TextBox, your neighbor's dog - well - almost. The only restrictions are
- Content can contain only one element at a time.
- Window.Content = AnotherWindow is not allowed.
So that's it. Now replace that //Super ToolTip code comes here comment with this code below:
TextBlock txt = new TextBlock();
CheckBox chk = new CheckBox();
chk.Content = "Cool?";
txt.Inlines.Add("\nLook, I have rich tooltips.\n");
tip.Content = txt;
btn.ToolTip = tip;
The GetWinSmartsLogo method simply returns an Image. Here's the code -
private Image GetWinSmartsLogo()
Uri uri = new Uri("http://blah.winsmarts.com/Images/logo_big.gif");
BitmapImage bmp = new BitmapImage(uri);
Image wsLogo = new Image();
wsLogo.Source = bmp;
Heh ! :-). Now check out the fancy tool tip yo !!
Heh !! Now if that ain't neat, I don't know what is.