WPF RichTextBox Performance WPF RichTextBox Performance wpf wpf

WPF RichTextBox Performance


You might need to consider using a different text box control.

Daniel Grunwald has written the Wpf text editor for SharpDevelop completely from scratch. It is called AvalonEdit and a good article is on codeproject:

http://www.codeproject.com/KB/edit/AvalonEdit.aspx

It seems that he has done optimizations for large files.


I bet Scintilla will outperform most (if not all) free alternatives out there. For WPF, use a WPF wrapper. E.g. ScintillaNET.WPF (haven't tried it though).

Pros

  • Excellent performance.
  • Great number of syntax highlighting schemes.

Cons

  • Don't expect native WPF features to work. E.g. scaling, touch...


AvalonEdit has much better performance and works with large input strings. Here is a minimal example:

MainWindow.xaml:

<Window x:Class="TestProject.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"        xmlns:local="clr-namespace:TestProject"        xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"        mc:Ignorable="d"        d:DataContext="{d:DesignInstance local:MainWindow}">    <avalonedit:TextEditor Document="{Binding Document}" /></Window>

MainWindow.xaml.cs:

using ICSharpCode.AvalonEdit.Document;namespace TestProject{    public partial class MainWindow    {        public MainWindow()        {            InitializeComponent();            DataContext = this;            Document.Text = "My string";        }        public TextDocument Document { get; } = new TextDocument();    }}