1

I have a RichTextBox that allows the user to type and edit and insert some complex UIElements that are wrapped in InlineUIContainer. The problem is when the user tries to delete/backspace one of the InlineUIContainers. I would like to disable deleting of these InlineUIContainers and I have another way for the user to delete them.

I have tried intercepting the deletion with the KeyEvents/PreviewKeyEvents, the textchanged event, the unload event of the UIElement. So far, they are not working because the deletion is trying to execute before those events are called.

rulestein
  • 409
  • 3
  • 12

1 Answers1

2

Try PreviewKeyDown:

    private void RichTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Delete)
        {
            e.Handled = true;
        }
    }
Mark Synowiec
  • 5,385
  • 1
  • 22
  • 18
  • This will make the delete button do nothing. What if you want to delete regular text in the rich text box, but not delete buttons and another UI elements? – martin36 Nov 02 '20 at 10:17