Q:

c# Syntax highlighting in WPF

I found a tutorial to do syntax highlighting in RichEdits for WPF:
http://blogs.microsoft.co.il/blogs/tamir/archive/2006/12/14/RichTextBox-syntax-highlighting.aspx
But if I open my list of commands from a file the Editbox becomes very very slow... maybe there are too much words to highlight.
I read that WPF elements like RichEdit are much slower than the WinForms elemts.
How can I make my WPF RichEdit faster OR include the Winforms RichEdit into my WPF?

A:

I wrote a similar syntax highlighter in .NET 1.1, and the performance is horrible.  I have not revisited the issue in many years, but it seems to me there must be a better way.  
I believe the answer may lie in the RTF documentation.  You can define color table and/or styles, and then use them to wrap the matching words.  Check out Page 130 "Font (Character) Formatting Properties", cfN and csN.  The trick then is to find the matches and insert the control characters as quickly as possible.  I'm RegEx would be the fastest scan method.
You could also try limiting the highlighting to a reasonable area around the visible space, or even consider Threading the highlighting action to another process.
I would definitely be interested in finding a good solution for this problem.

