保护WPF richtextbox中的文本 [英] Protecting text in WPF richtextbox

查看:149
本文介绍了保护WPF richtextbox中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成的FlowDocument我希望用户能够在某种程度上添加和编辑,但很多生成的内容不应该是可编辑的。



有没有人知道在RichTextBox中保护文本的可靠方法?



我尝试过的方法:



我尝试在单个流文档块上捕获MouseDown事件,这似乎大部分时间都可以工作但如果我反复点击并用鼠标拖动,我最终可以得到一些受保护的文字突出奇怪的是,当发生这种情况时,Snoop没有显示任何其他事件触发,我看不到任何模式何时发生,何时不发生。



这实际上并不是一个好的解决方案,即使它确实按预期工作,因为它不会阻止突出显示从相邻的不受保护的块中拖出。< br $>


RTF标记中有一个保护属性,但在代码中添加一个块并尝试操作RTF代码的想法时,我看不到添加它的任何方法正则表达式听起来像是一生的任务。我怀疑我不得不将文档中受保护和未受保护的部分分解为单独的控件但这样会非常不整洁,并且仍会留下我需要保护文本部分而不是整个部分的问题阻止或段落。

I have a generated FlowDocument that I would like users to be able to add to and edit to some extent but much of the generated content should not be editable.

Does anyone know of a reliable way of protecting text within a RichTextBox?

What I have tried:

I've tried catching the MouseDown events on individual flow document blocks and this seems to work most of the time but if I repeatedly click and drag with the mouse, I can eventually get some of the "protected" text highlighted. Curiously, when this does occur, Snoop is not showing any additional events firing and I can't see any pattern in when it occurs and when it doesn't.

This wouldn't actually be a good solution even if it did work as intended because it wouldn't prevent the highlight being dragged over from an adjacent unprotected block.

There is a protect attribute in RTF markup but I can't see any way of adding it whilst adding a block in code and the idea of trying to manipulate RTF code by regex sounds like a lifetime task. I'm suspecting that I'll wind-up having to break protected and unprotected portions of the document down into separate controls but that would be extremely untidy and would still leave issues with areas where I just need to protect portions of text rather than entire blocks or paragraphs.

推荐答案

目前还不清楚你想要达到的目的。

你能用两个富文箱,一个是读 - 只有框用于显示常量内容,另一个用于可编辑内容附近/下方?

一旦用户准备就绪,你就可以简单地合并两个控件的内容。



这简直就是解决问题的方法吗? br $> b $ b

[已编辑]

请查看此解决方案: RichTextBox中的字符串保护



建议:



为什么不在RichText中使用控件框?你可以插入按钮和其他控件,所以我想插入Label或TextBlock可能会做你需要的。





答案:

我试过在RichTextBox中放置一些控件并添加一些代码来保护控件不被删除,并且它有效。
That is not exactly clear what you try to achieve.
Can you use two richboxes, one as read-only box just to show the "constant" content and another one nearby / below with the editable content?
As soon as the user is ready, you simple merge the content of both controls.

Would this simply trick solve the problem?


Please take a look at this solution: String protection in RichTextBox .

Suggestion:

Why don't you use a control inside the RichText box? you can insert buttons and other controls, so i guess inserting a Label or a TextBlock might do what you require.


Answer:
I tried to put some controls in RichTextBox and added some code to protect controls from being deleted, and it worked.


这篇关于保护WPF richtextbox中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆