[英]WPF RichTextBox tokenized editing
I am trying to enable the user to edit specific parts of a text (and only those parts) using a RichTextBox
control. 我试图让用户使用
RichTextBox
控件编辑文本的特定部分(并且只编辑那些部分)。
My approach consists of using TextBox
controls contained in InlineUIContainer
tags in a FlowDocument
. 我的方法包括在
FlowDocument
中使用InlineUIContainer
标记中包含的TextBox
控件。 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. 这个问题是用户能够选择
FlowDocument
的元素并删除它们...更糟糕的是,他们可以编辑任何属于Run
元素的文本,甚至可以剪切/粘贴文档中的文本。
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). 我有想法在
RichTextBox
上设置IsReadOnly="True"
,但也禁止TextBoxes被编辑...我也可以处理PreviewKeyDown但是无法处理所有情况(即:右键单击并按下粘贴)。
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
?: 如何将
TextBox
的IsReadOnly
属性设置为false
并将RichTextBox
的IsReadOnly
属性设置为true
IsReadOnly
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.