views:

150

answers:

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.

+1  A: 

Try PreviewKeyDown:

    private void RichTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Delete)
        {
            e.Handled = true;
        }
    }
Mark Synowiec