0

I've started my journey for searching an efficient way to output logs.

The problem: Implement smth like VS Output window.

I've tried to use the RichTextBox and I really don't like how it performs. It is hard to implement some sort of virtualization in case the output is really long. So, this control is not created for such tasks.

This task seemed to me really easy until I decompiled the original OutputWindow control in VS and realized that there are a couple of thousand lines of code. Probably, there is a way to initialize it inside my WPF application, but styles end etc...

TextBox - doesn't fit also.

I've rushed through google and GitHub haven't found anything... I really don't believe I am the first person who faces such a problem.

So, maybe smb seen smth similar?

Thanks in advance!!

P.S. Right now I've resolved it by using templated ListBox. That is not what I need, but performs the best.

Baranovskiy Dmitry
  • 463
  • 2
  • 5
  • 23
  • Using a styled ListBox is the best. It gives you UI virtualization, is read-only and will look like a document if styled accordingly e.g. by removing the highlighting. When you define an item template to use a TextBlock that binds to a corresponding item model, you can even use rich text formatting to display the items. – BionicCode Sep 20 '22 at 11:30
  • 1
    [This solution](https://stackoverflow.com/a/69541760/3141792) also provides an efficient way to read large log files (by reading from the file in parallel). – BionicCode Sep 20 '22 at 11:33
  • You can also implement your own VirtualizingStackPanel based control. You definitely want some sort of virtualization as log files can be quite big. TextBox, TextBlock and RichTextBlock are not optimized for this task. – BionicCode Sep 20 '22 at 11:35
  • If you need to stay with a FlowDocument you should use the FlowDocumentScrollViewer instead of the RichTextBox. Another very fast solution is to use low-level text rendering techniques like Glyph drawing or [Drawing Formatted Text](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/drawing-formatted-text?view=netframeworkdesktop-4.8). But this will need some effort (although it will be quite simple for a read-only fixed formatting text output). – BionicCode Sep 20 '22 at 11:43
  • Very cool, probably will try your approach with Listbox. But still, it is strange that there is not ready2go Output-control.. or smth like that. And again, as I mentioned about - VS has own. I didn't investigate how it is implemented but assumed it is a custom drawing contept. – Baranovskiy Dmitry Sep 20 '22 at 11:53

0 Answers0