I have a RichTextBox displaying a FlowDocument that is large (>10k lines). I am attempting to apply text formatting to the entire Document. This is taking a while to complete.
Is there any way to focus the formatting on the visible parts of the Document only?
For Information: I am attempting to search through the contents of the RichTextBox and highlight all matching occurrences. The searching function is baised upon this one. I am using the following code to 'highlight' each match found.
protected void ColorTextRanges(Color color)
{
foreach ( var textRange in locatedInstances )
{
if ( textRange != null )
{
textRange.ApplyPropertyValue( TextElement.BackgroundProperty, new SolidColorBrush( color ) );
}
}
}
The best performance increase I found was to update the document when out wasn't displayed on the screen. Not sure sure why this is but I can guess that some thing in the screen buffer isn't being updated.