WPF RichTextBox –迭代文本的单词并更改其内容和格式
我有一个 WPF RichTextBox,其 FlowDocument 中包含文本和图像。我需要迭代文本的单词(那些构建用户在屏幕上看到的文本的单词)并更改其内容和格式。例如,将单词“房间”更改为单词“家”,最后应用红色。
我需要更改单词,无论它们是格式化还是未格式化。 例如,如果一个单词是斜体、彩色或只是普通的黑色文本,这对我来说没有什么区别。
每个单词将被替换为长度大致相同的单词, 所以我不希望此操作会影响总体页面布局。所有图像和其他对象应保持在其位置。
最好该操作的过程对用户不可见。只有其结果应该是可见的(即,没有可见的文本选择)。
如果此操作可以直接在 FlowDocumet 上完成或使用 RichTextBox 的属性/方法完成,则首选简单的操作(但两者的示例都将是理想的)。
VB 代码示例很棒,但 C# 也很受欢迎。
多谢
I have a WPF RichTextBox which contain in its FlowDocument both text and images. I need to iterate through the text's words (those which builds the text which the user see on the screen) and change their content and formatting. For instance, change the word "room" to the word "home", applying to the last a red color.
I need to change words whether they are formatted or unformatted.
For instance, if a word is in Italic, colored, or just regular black text, it makes no difference for me.Each word will be replaced with one which have about identical length,
so I don't want that this operation will effect the general page layout. All images and other objects should remain at their positions.It is preferred that the process of this operation will not be visible to the user. Only its result should be visible (i.e, no visible selections of text).
If this operation can be done either directly on the FlowDocumet or with properties/methods of the RichTextBox, the simple one is preferred (but exmaples for both will be ideal).
VB code examples will be great, but C# is welcome as well.
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个困难的问题,因为 WPF 没有内置标准文本搜索。但是,此链接可能会提供一些答案。
http://social .msdn.microsoft.com/forums/en-US/wpf/thread/a2988ae8-e7b8-4a62-a34f-b851aaf13886#search_text
This is a tough one, since WPF doesn't have standard text search built right in. However, this link may provide some answers.
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/a2988ae8-e7b8-4a62-a34f-b851aaf13886#search_text