Q:

WPF textbox spellcheck is highlighting the whole text rather than changing the word

I am having a problem with some of my textboxes.  I have enabled Spell Checking on them and when a word is misspelled it is underscored red and right-clicking will give me a choice of replacement words.  This is all good and as expected.
The trouble I have is that when I select a replacement word, instead of correcting my text, the whole block of text becomes highlighted and the word remains unchanged.
This isn't happening in all my textboxes and, strangely, if it is the first word in the sentence that is misspelled then the spell checker works as intended and correctly replaces the word.
<TextBox x:Name="TxtBugDescription" Grid.Row="3" Grid.Column="1" TextWrapping="Wrap" Padding="3" SpellCheck.IsEnabled="True" Margin="5" VerticalAlignment="Stretch" AcceptsReturn="True" />

Any ideas on how to fix this?

A:

We just had this issue as well! Thanks to Spellcheck only replaces first word in TextBox, we finally figured it out.
We had this code in our App.xaml.cs which highlights (selects) all text in a textbox whenever it gets focus. This seemed to be what was throwing off the spell checker. 
//In the App.xaml.cs file
EventManager.RegisterClassHandler(typeof(TextBox), UIElement.GotKeyboardFocusEvent, 
    new RoutedEventHandler(SelectAllText));

private static void SelectAllText(object sender, RoutedEventArgs e)
    {
        var tb = (sender as TextBox);
        if (tb != null)
            tb.SelectAll();
    }

We decided the primary use case for this code for us was when tabbing through a form, so we changed it to only happen on tab which allows the spell check to still work. 
//Changed the method to only set focus when the tab was pressed
private static void SelectAllText(object sender, RoutedEventArgs e)
{
    if (e.RoutedEvent == Keyboard.GotKeyboardFocusEvent)
    {
        if (!Keyboard.IsKeyDown(Key.Tab))
            return;
    }
    var tb = (sender as TextBox);
    if (tb != null)
        tb.SelectAll();
}

Others may want to just remove it.

