Question

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.

No correct solution

OTHER TIPS

Try PreviewKeyDown:

    private void RichTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Delete)
        {
            e.Handled = true;
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top