Today I was trying to add a simple tooltip to a bunch of small Canvas' in my Silverlight project. After a little digging I found that
- (a) there is a .NET class called Tooltip which does this functionality for me and
- (b) many controls lack a ToolTip property [such as TextBox, TextBlock, Canvas etc...]
// Create a TooltipNote, you may need to add the System.Windows.Controls reference to your project for this to work... I can't recall if that assembly is added by default when you create a project in VS2008.
ToolTip nameTip = new ToolTip();
// Set the content [here I use text, but apparently it can be more complex]
nameTip.Content = "Testing ToolTipService";
// Use ToolTipService to attach the ToolTip to my Canvas.
ToolTipService.SetToolTip(myCanvas, nameTip);
ToolTipService Documentation
2 comments:
//add this ref to project
System.Windows.Controls.Extended
//using a TextBlock for ToolTip
//Adding to an Image
//Adding Image to ListBox
TextBlock tb = new TextBlock();
tb.Text = "your text here"
//Now add using ToolTip Service
ToolTipService.SetToolTip(Image, tb);
//add to Listbox
ListBox.Items.Add(Image);
Works for me.
//My Goof forget adding this ref
System.Windows.Controls.Extended
Just make sure System.Windows.Controls
is referenced in your project
Post a Comment