如何在 WPF 中处理/编辑大量文本? [英] How do I handle/edit large amount of text in WPF?

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

问题描述

使用 WPF 显示和编辑大量无格式文本(就像记事本一样)的好方法是什么?将大字符串加载到 TextBox 会使 UI 无响应.整体性能几乎无法与以前的 Microsoft UI 框架的 TextBox 控件相媲美.

What would be a good approach to display and edit large amount of unformatted text (just like notepade does) using WPF? Loading a big string into a TextBox makes the UI unresponsive. The overall performance is not nearly comparable with TextBox Controls of previous Microsoft UI Frameworks.

我有什么选择来解决这个问题.我不想在文本控件加载文本时阻塞 UI 线程.此外,我可能需要某种虚拟化",因为将整个文本加载到控件中可能不是一个好主意(我猜 20MB 的文本会创建很多字形,即使它们不可见).似乎 TextBox 甚至没有 AppenText() 方法了,所以我什至没有办法控制文本的异步加载.

What options do I have to solve this problem. I do not want to block the UI thread while the text control loads the text. Also I might need some sort of "virtualization" because it might not be a good idea to load the whole text into the control (I guess that 20MB of text would create a lot of glyphs even if they are not visible). It seems that TextBox doesn't even have an AppenText() Method anymore so I don't even have a way to control asynchronous loading of the text.

这不是一个普遍的问题吗?似乎 WPF 没有为此提供任何开箱即用的功能.为什么会这样?

Isn't this a common problem? It seems that WPF does not provide anything for this out of the box. Why is this so?

推荐答案

AvalonEdit,SharpDevelop 中的文本编辑器,完全用 WPF 从头开始​​编写,并针对大量文本进行了优化.它不支持富文本(尽管它确实支持语法高亮和其他很酷的功能,例如折叠).我认为这可能完全符合您的要求.

AvalonEdit, the text editor in SharpDevelop, was written completely from scratch in WPF and is optimized for large amounts of text. It doesn't support rich text (although it does support syntax highlighting and other cool features such as folding). I think this might fit your bill perfectly.

以下是开发者撰写的关于编辑器的文章:

Here is an article on the editor written by the developer:

http://www.codeproject.com/KB/edit/AvalonEdit.aspx

这篇关于如何在 WPF 中处理/编辑大量文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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