Silverlight 2 - Tooltips revisited for beta 2

June 12, 2008 18:12 by Corey

I had a post earlier on silverlight 2 and the tooltip service. With beta 2 the game has changed, slightly... first buttons and other controls lost the tooltip property. Meaning you cannot simply say Tooltip="Hello World" like before. Now all items including layout controls like canvas, graphic elements like rectangle, and even controls like button all use the tooltip service. They made a tooltip service much easier to implement by removing the need for referencing the control dll like in beta 1. Now all you have to do is the following:

1. In the object you want to add the Tooltip functionality, inside its container specify the tooltip service; however, the tooltip property of the tooltip service wants to be set to an instance of a tooltip object and not a string:

<Canvas x:Name="SomeCanvas" Background="Green" Width="100" Height="100">

<control:ToolTipService.ToolTip>
     <ToolTip Content="Hello World" />
</control:ToolTipService.ToolTip>

</Canvas>



And viola, a canvas now has a Tooltip property.


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

September 3. 2008 22:00

Scott Edmondson

Hey Cory,

Thanks for that. It works like a charm! I must admit I would never have thought of that particular syntax--especially since VStudio (or ReSharper?) is telling me "ToolTipis not accessible" [sic] when I use your approach on a sub-class of the TextBox control.

Scott Edmondson

September 4. 2008 11:16

Corey

Yeah, that is actually a bug in beta 2 that will be remedied in RTM. There are several approaches to tooltips in beta 2, I have a video that walks through them.

Corey

September 23. 2008 12:20

Bradford

Thanks! Worked like a charm.

Bradford

September 23. 2008 12:34

Bradford

btw, you might want to remove the "control" from the ToolTipService part of your xaml, as it is now unnecessary.

Bradford

Add comment


(Will show your Gravatar icon)  

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

November 21. 2008 03:04