I know I have seen this problem before somewhere, but I'm not sure if there was an answer at the time. I'm trying to add SpellCheck to a TextBox
in WPF, .NET 4.0. It works fine in terms of finding and marking the incorrect words, and will replace the first word in the TextBox
if it's incorrect. Anything past word one though, and it just moves the carat to the start of the TextBox
without changing anything? As I said I saw this somewhere about 6-9 months ago, but now everything I come up with in google deals with alternate languages (I'm staying strictly in English for now). I've included the event methods and styling XAML only for completeness, I don't think the issue lies there.
XAML:
<MultiBox:MultiBox Name="callNotes" Grid.Column="1" Width="Auto" Height="Auto" Margin="2,5,15,20" VerticalAlignment="Stretch" AcceptsReturn="True" FontWeight="Bold" GotFocus="callNotes_GotFocus" SelectAllOnGotFocus="False" SpellCheck.IsEnabled="True" xml:lang="en-US" Style="{StaticResource TextBoxStyle}" TextChanged="callNotes_TextChanged" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" />
<Style x:Key="TextBoxStyle" TargetType="{x:Type MyNamespace:MultiBox}">
<Setter Property="CharacterCasing" Value="Upper" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Height" Value="23" />
<Setter Property="Width" Value="Auto" />
<Setter Property="SelectAllOnGotFocus" Value="True" />
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
Code:
private void callNotes_TextChanged(object sender, TextChangedEventArgs e)
{
callNotes.Text.ToUpper();
lineCountOne.Content = ((callNotes.Text.Length / 78) + 1);
}
private void callNotes_GotFocus(object sender, RoutedEventArgs e)
{
callNotes.CaretIndex = callNotes.Text.Length;
}
After trying jschroedl's suggestion and still having no luck (although I do know that his answer should have been correct), I started playing with every possible setting I could think of, even to the point of creating a completely new WPF project with a single,
Spellcheck
-enabledTextBox
just to make sure it wasn't something with the Visual Studio/.NET installation itself. Turns out it wasn't, it was something I had done months ago to ensure that selecting any givenTextBox
through the program would result in theSelectAll()
method being triggered. Once I screened out this particularTextBox
from that bit of code, all works great. Again, thanks to jschroedl, I know there is no way he could have known this. The offending code is below, in case anybody comes across a similar issue.Adding the && textBox.Name != "callNotes" solved the problem.
It would help to see your code which attempts to correct the errors. Here's simple code which loops through all the detected errors and accepts the first suggestion. If you only want to fix particular errors, you'll need to skip to the particular error you're interested in by getting the error at a certain index.