WPF RichTextBox - get whole word at current caret position
问题 I enabled spelling on my WPF richtextbox and I want to get the misspelled word at current caret position before the context menu with spelling suggestions is displayed. 回答1: The new way void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Back) { TextPointer start = richTextBox1.CaretPosition; string text1 = start.GetTextInRun(LogicalDirection.Backward); TextPointer end = start.GetNextContextPosition(LogicalDirection.Backward); string text2 = end.GetTextInRun