文本框部分可编辑 [英] TextBox Partially Editable
问题描述
是否可以使 TextBox
或 RichTextBox
的内容部分可编辑?例如,我想要如下所示的内容:
Is it possible to make the contents of a TextBox
or a RichTextBox
parially editable? For instance, I would like to have something that looks like the following:
<TextBox TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" FontFamily="Courier New" Margin="10,0">
This text and anything before it isn't editable.
This Text is Editable
This text and anything after it is not editable.
</TextBox>
或类似的东西:
<RichTextBox AcceptsReturn="True" VerticalScrollBarVisibility="Auto" FontFamily="Courier New" Margin="10,0">
<FlowDocument>
<Paragraph>This text and anything before it is not editable.</Paragraph>
<Paragraph>This text is editable.</Paragraph>
<Paragraph>This text and anything after it is not editable.</Paragraph>
</FlowDocument>
</RichTextBox>
理想情况下,我可以设置与不可编辑文本不同的可编辑文本的样式.在有人告诉我不应该这样做之前,我有这样做的正当理由.
Ideally, I would be able to style the editable text different than the uneditable text. Before anybody tells me I shouldn't do this, I have a valid reason for doing it.
提前致谢.
推荐答案
您应该能够将三个控件封装到一个可滚动区域并根据需要调整可编辑字段的大小(即,可编辑字段没有滚动,只有包含地区).
You should be able to encapsulate the three controls into a scrollable region and resize your editable field as needed (i.e., the editable field has no scrolling, only the containing region).
它不是很漂亮,特别是如果没有使用 XAML 的简单方法(我从未使用过它,所以我不能说),但我认为它比试图破解这个要好得多进入(丰富的)TextBox.
It's not very pretty, especially if there isn't an easy way of doing it with XAML (I've never used it, so I can't say), but I would content it's far better than trying to hack this thing into (Rich)TextBox.
这篇关于文本框部分可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!