开发者

Prevent delete/backspace of InlineUIContainers in RichTextBox (WPF)

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开发者_StackOverflow中文版 because the deletion is trying to execute before those events are called.


Try PreviewKeyDown:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜