views:

237

answers:

2

I'm looking to display text with the wavey red lines where a word is misspelt, but I only want the text to be selectable, not editable. If I set the TextBox's IsReadOnly property to True or IsEnabled to False, the wavey red lines disappear and I can't get around it by putting something transparent as this will prevent the user being able to select sections of the text.

Is there anyway I can keep the red lines, allow the text to be selectable but prevent the actual text being modified?

Thanks

+1  A: 

You could hook up to on the text change event of the text box, and just reject the new text. It would have the same effect of readonly without graying out the textbox or getting rid of the spell checking.

David Basarab
A: 

Thanks David. I'm currently looking at 2 possible solutions, yours and the following:

I've created a custom control which is based on the standard TextBox, but effectively has 2 textboxes laid on top of one another in this manor:

<TextBox Name="tbxBack" 
         Foreground="Transparent"
         SpellCheck.IsEnabled="True"
         TextWrapping="Wrap" 
         SnapsToDevicePixels="True"/>
<TextBox Name="tbxFront" 
         Background="Transparent"
         TextWrapping="Wrap" 
         SnapsToDevicePixels="True" 
         IsReadOnly="True"/>

I think it's pretty straight forward what's going on here, but I'm concerned about the potential overhead this will cause.

The reason I'm looking into the double TextBox solution is that I'm worried if I try and cancel the event, it could end up with some sort of flashing in the control when the text is changed.

Tom Allen