Are there rendering issues when storing a sizeable amount of text in a Rich Text Box using WPF?

StackOverflow https://stackoverflow.com/questions/22635607

  •  20-06-2023
  •  | 
  •  

سؤال

Afternoon all;

So, I have been developing an application using C# and WPF. I am using a Rich Text Box to display a fair amount of static text, say roughly 1000 lines (lines being between 10 and 30 words)

I am inserting the text by saving it inside a text file. Then reading that text file and saving it to a string variable. That string variable is then put inside a FlowDoc, like so:

public void fillTimeline(RichTextBox timeline)
{
    FlowDocument myFlowDoc = new FlowDocument();

    string x = System.IO.File.ReadAllText(@"path");

    myFlowDoc.Blocks.Add(new Paragraph(new Run(x)));

    timeline.Document = myFlowDoc;
} 

Once I built and ran the application, I see that the text is extremely fuzzy, and almost unreadable. Like this

However this issue does not occur if I reduce the lines to about 500. Is there an issue displaying that much text within a RichTextBox?

I have tried a few things to resolve the issue

  1. Setting FormattingMode to all available options.
  2. Enabling ClearType
  3. Trying all 3 TextRenderingModes

Is this a known issue? Is there anything I may be able to try. I am out of ideas now.

Thanks.

هل كانت مفيدة؟

المحلول

Try reading the text a line at a time

List<String> Lines = new List<String>();
System.IO.StreamReader file = 
   new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
   myFlowDoc.Blocks.Add(new Paragraph(new Run(x)));
   Lines.Add(line);
}

file.Close();

Try using a FlowDocumentScrollViewer rather than RichTextBox

Try just using Lines with a ListBox with TextBlock
With virtualization it performs nicely

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top