Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I handle/edit large amount of text in WPF?

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.

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.

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

like image 667
bitbonk Avatar asked Feb 03 '23 11:02

bitbonk


2 Answers

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

like image 153
Patrick Klug Avatar answered Feb 06 '23 09:02

Patrick Klug


I am not sure if this helps, but have you tried using FlowDocumentPageViewer and FlowDocumentReader?

It also has very good annotations support and looks ideal for loading documents in text format.

like image 20
Vin Avatar answered Feb 06 '23 09:02

Vin