We are developing a .Net 4.0 C# WPF Line-of-business app and need to show (readonly) large text files to the user. TextBlock
as stated in SO is not an option and tried the suggested AvalonEdit control. Running the AvalonEdit.Sample standalone app can load a 4MB file with 8k lines in less than a second, but when embedding the AvalonEdit TextEditor
into our WPF app spends 20 seconds, almost the same as the previous TextBlock
.
The UI is quite complex, with a splitter for tree-menu and forms. The form has several splitters to create resizable zones and one of them contains a tab control. One of the tab items has the TextEditor
from AvalonEdit.
XAML
<avalonEdit:TextEditor Name="Tbx" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" />
CS
public void ShowFile(string path)
{
Tbx.Text = string.Empty;
ThreadPool.QueueUserWorkItem(o => {
var lines = File.ReadAllLines(path).Join("\n");
Dispatcher.BeginInvoke(() => Tbx.Text = lineas);
});
}
When loading the file, my laptop i7 4-core CPU usage is 33%.
Any suggestion about the different behaviour of AvalonEdit TextEditor
as standalone app and within a custom WPF app?
How to load large files (10MB, 10k lines) with TextEditor
?
UPDATE:
The Visual Tree:
The properties of the TextEditor
:
I removed a ScrollViewer that host the TextEditor
as pointed, but same poor performance is achieved.
UPDATE 2:
I moved the TextEditor
to a new window to reduce the layout but still get poor performance.
The new, simplified Visual Tree:
Grid
column and row definition is *
.
The properties of the TextEditor
: