问题描述
我有一个可以在不同选项卡中打开多个文本文件的应用程序.我在处理应用程序中的数据时使用RichTextBox.但是,加载大文本文件(10MB)会使整个UI变慢.有办法解决这个问题吗?我在想偷懒 加载文件,因此,当用户按下滚动按钮时,必须加载文件的后续部分.有什么地方可以开始使用这种方法吗?请帮助我,我对WPF和C#编程还很陌生.
I have an application which opens multiple text files in different tabs. I use RichTextBox while processing this data in my application. However, loading large text files(10MB) slows the entire UI. Is there a way to solve this problem? I am thinking of lazy loading the file, so when the user presses the scroll button, later part of the file has to be loaded. Is there a place where I can start with this approach? Please help me I am pretty new to WPF and C# programming.
RichTextBox mcRTB = new RichTextBox();
rtbList.Add(mcRTB);
mcRTB.SelectionChanged += mcRTB_SelectionChanged;
TabItem tab = new TabItem();
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(System.IO.File.ReadAllText(filePath));
FlowDocument document = new FlowDocument(paragraph);
mcRTB.Document = document;
StringBuilder dataContent = new StringBuilder();
//此语句需要几秒钟,需要查找替代方法dataContent.Append(new TextRange(mcRTB.Document.ContentStart,mcRTB.Document.ContentEnd).Text);mcRTB.TextChanged + =新的System.Windows.Controls.TextChangedEventHandler(SegFileDataContentChanged);tab.Content = mcRTB;
//this statement takes few seconds, need to find alternativesdataContent.Append(new TextRange(mcRTB.Document.ContentStart, mcRTB.Document.ContentEnd).Text);mcRTB.TextChanged += new System.Windows.Controls.TextChangedEventHandler(SegFileDataContentChanged);tab.Content = mcRTB;
推荐答案
这篇关于RichTextBox减慢了整个UI的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!