I am trying to enable the user to edit specific parts of a text (and only those parts) using a RichTextBox
control.
My approach consists of using TextBox
controls contained in InlineUIContainer
tags in a FlowDocument
. The code below shows what I've accomplished so far:
<RichTextBox IsDocumentEnabled="True">
<FlowDocument>
<Paragraph>
<InlineUIContainer >
<TextBox Text="Field" MinWidth="65"></TextBox>
</InlineUIContainer>
<InlineUIContainer>
<TextBlock Text="Some text..." ></TextBlock>
</InlineUIContainer>
</Paragraph>
</FlowDocument>
</RichTextBox>
The problem with this is that the user is able to select the elements in the FlowDocument
and delete them... worse they can edit any text that is part of a Run
element or even cut/paste text in the document.
I had the idea to set the IsReadOnly="True"
on the RichTextBox
but that also disables TextBoxes from being edited... Also I could handle the PreviewKeyDown but that can not handle every situation (ie: Right clicking and pressing paste).
I was wondering if there is any alternative solution or even an alternative library or third party control that helps.
How about setting the IsReadOnly
property of the TextBox
to false
and the IsReadOnly
property of the RichTextBox
to true
?:
<RichTextBox IsDocumentEnabled="True" IsReadOnly="True">
<FlowDocument>
<Paragraph>
<InlineUIContainer >
<TextBox Text="Field" MinWidth="65" IsReadOnly="False"></TextBox>
</InlineUIContainer>
<InlineUIContainer>
<TextBlock Text="Some text..." ></TextBlock>
</InlineUIContainer>
</Paragraph>
</FlowDocument>
</RichTextBox>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.