9

I would like an efficient log-viewer control in WPF that simply shows a live log as messages are being added. It is no problem to hook up to notifications from the log-system, but I am worrying that a log window will come to a crawl with each appending log-line once the number of log-lines grow large.

The log notification events will simply provide a log string (along with some meta) that I want to append to the lines in a TextBox or similar with a scroll bar. Assuming plenty of memory, appending a large number of lines should not be a memory problem, but I would not like the system slowing down once line number 10,000 is being added.

I assume that binding a TextBox to a simple string dependency property will get rather slow once the string is getting into MB size and thousands of lines.

How could I write such a control efficiently in WPF?

Holstebroe
  • 4,993
  • 4
  • 29
  • 45
  • Related: [What is a fast way to render a log view in WPF?](http://stackoverflow.com/questions/430609/what-is-a-fast-way-to-render-a-log-view-in-wpf) – publicgk May 13 '11 at 09:05

1 Answers1

11

why not use a listbox? create a collection where you add your log message every time and just bind this collection to your itemscontrol itemssource.

EDIT: i use a datagrid in my projects to show messages coming from WCF service

EDIT2: some Itemsscontrols have the following property which should help:

<ListBox VirtualizingStackPanel.IsVirtualizing="True" />
blindmeis
  • 22,175
  • 7
  • 55
  • 74
  • Is a list box efficiently updating when adding line number 10,000? If so, I guess it should work. – Holstebroe May 13 '11 at 08:55
  • well you are updating your collection but not the itemsscontrol directly :) in your ui you just see a little subset of the whole collection. Virtualizing is the key. see my EDIT2 – blindmeis May 13 '11 at 09:27