13 Comments Already

commenter
eburke Said,
September 19th, 2008 @9:02 am  

hey aaron, i like the solution. there are a couple cases where unhooking the Loaded handler inside the Loaded handler will bite you.

1. if you are assigning the tooltip in a trigger, the owner will already be loaded and you won’t be able to update the data context. you could get around this by checking if the owner is already loaded or not at the time the data context is applied.

2. there are times where, if you are in a data bound ItemsControl and you Move() data items within the data collection, the container items will actually get Unloaded and then Reloaded (i guess the generator is smart enough to reuse the container). in this case, you’ll get bit by unhooking the Loaded handler. [in this case you have to go so far as to set a timer and check IsLoaded at that time so that you are *sure* the item has really been unloaded.

case 1 is way more common than case 2, but case 2 is really hard to debug. ;)

commenter
Aaron Said,
September 19th, 2008 @10:29 am  

Thanks for pointing out a few of the cases that I suggested exist, but didn’t handle.

Are you saying that you actually do a trigger where the TooltipServer.Tooltip property is set to a new tooltip? I just want to make sure I understand what you’re saying.

For the second case — the visuals are destroyed and recreated for a moved item aren’t they? Since the tooltip is attached to the root datatemplate visual, it would be newly created (and hence the load would work).

The extension the code I wanted to write this morning (but had to leave for work), was that it would double check that the control needed the loaded event handler method — if the “owner” FrameworkElement already had a datacontext (or a visual parent), then it’s probably not necessary to use the loaded event technique at all.

commenter
September 19th, 2008 @11:11 am  
commenter
poems Said,
October 1st, 2008 @11:02 am  

I didn’t have this solution, now I will have it. thanks

commenter
Rammesses Said,
October 22nd, 2008 @5:30 am  

Nice work! Compared to all the hastle of building rich tooltips in ASP.Net (even using the AJAXControlToolkit), this is a breeze. Thanks!

commenter
Anesh Said,
November 3rd, 2008 @2:21 pm  

Thank you for posting this wonderful solution. I have tried it and it works well except for when there is scrolling region. I have a datagrid and and when there are large number of rows, when one scrolls down the tips seem to stuck to the original visible area. This may be related to eburke’s and your comments. Do you have any ideas/solutions for this issue?
Thank you.

commenter
John R Said,
February 6th, 2009 @3:35 pm  

I also thank you. This is the first approach that worked for me. I have a tree view with images at each node. I wanted a tooltip to appear when hovering over those images. I couldn’t get a tooltip to bind dynamically (unless simply a property of the image control itself which prevented proper styling), until I tried your solution.

Many thanks!

commenter
February 15th, 2009 @6:30 pm  

Thanks for the post, I got it to work after a couple of failed attempts from someone elses similar post. Much appreciated!

cheers,
Stephen

commenter
Carl Ryden Said,
February 27th, 2009 @4:45 pm  

Thank you. This is great. I owe you one.

commenter
Roboblob Said,
May 13th, 2009 @1:56 am  

Thanks, very nice solution.
Hope MS will fix this in SL3.

Cheers!

commenter
October 8th, 2009 @9:22 am  

Thank you, your post is very usefull for me. My previous solution was not same correct (had some bugs).

commenter
tomking Said,
October 12th, 2009 @9:23 pm  

Hello everybody!
I create a new app and copy the code above to run ,
but can’t compile pass successfully. Please help me to check ,thanks !
Error info:
The property ‘Tooltip’ does not exist on the type ‘StackPanel’ in the XML namespace ‘clr-namespace:SilverlightApplication2′.

Pingback & Trackback

Related Post

Please Leave Your Comments Below

Please Note: All comments are moderated, so it may take some time before your comment appears.