Hello.
Hi! I am trying to cancel (prevent) some text editing in RichTextBox. I am using TextChanged event, but I did not find the way how to cancel or rollback some changes, any ideas?
private void mainRTB_TextChanged(object sender, TextChangedEventArgs e)
{
TextRange text = new TextRange(mainRTB.Document.ContentStart, mainRTB.Document.ContentEnd);
if (text.Text.Length >= this.MaxLenght)
{
mainRTB.Document.ContentEnd.DeleteTextInRun(-1);
mainRTB.IsReadOnly = true;
}
}
By executing mainRTB.Document.ContentEnd.DeleteTextInRun(-1); does not delete any text.
mainRTB -> System.Windows.Controls.RichTextBox
Thks