views:

226

answers:

1

Hi, when hovering my mouse over a wrapped textbox, I want to get the word or text position immediately under the mouse.

I've seen some samples for a single textbox, like this one, but I have a wrapped textbox. I think I might be able to do this if I had a MeasureString function but I don't have that either in Silverlight (would be useful for other things).

Example TextBox

 <Textbox TextWrapping="Wrap" Width="50" Text=" ... " />
A: 

There isn't this ability in Silverlight today. Here's what I would do as a workaround:

  1. Have an invisible (Opacity 0, IsHitTestVisible=False) WrapPanel with a TextBlock for each word.
  2. Make the WrapPanel the same size as the TextBlock
  3. Adjust margins on the TextBlocks and WrapPanels until you get similar spacing.
  4. Do hit testing on the WrapPanel with the TextBlocks to determine the word
Michael S. Scherotter
Thanks for the advice. It seems expensive but I will give it a try and get back with my results. Also, I'm using a TextBox, not a TextBlock so I'm hoping it's not too much work to try to simulate the exact spacing for 2 different controls. We shall see.
Paully