void RichTextBox_TextChanged(object sender, TextChangedEventArgs e) { //This fixes the bug when applying text transformations the text would lose it's highlight. That was because the RichTextBox was losing focus, //so we just give it focus again and it seems to do the trick of re-highlighting it. if (!_richTextBox.IsFocused && !_richTextBox.Selection.IsEmpty) { _richTextBox.Focus(); } }