Tuesday, May 10, 2016

Remove formatting of last selected text in a WPF RichTextBox control

Here's how to remove the formatting of last selected text in a WPF RichTextBox control from it's SelectionChanged event.
C# Code
1
2
3
4
5
6
private void rtbEditor_SelectionChanged(object sender, RoutedEventArgs e)
{
    //Clear previous selections.
    TextRange textRange = new TextRange(rtbEditor.Document.ContentStart, rtbEditor.Document.ContentEnd);
    textRange.ClearAllProperties();
}

Output

0 comments:

Post a Comment