ListBox scrolling behavior is bad with large ListBoxItems

467 views Asked by At

I'm currently using a virtualizing ListBox as a text output window - basically a replacement for RichTextBox, since RichTextBox is extremely slow, and there are no valid replacements for it - see this question: How do I increase performance of FlowDocumentScrollViewer?.

The problem I'm running into is when very large strings are printed, the height of the ListBoxItem that holds the string increases as well because its width is constrained inside the window. As the height of the ListBoxItem increases, the scrolling behavior of the ListBox itself decreases in usefulness rapidly, and a number of bugs show themselves. When the height of the ListBoxItem approaches the height of the ListBox, I get flickering and the ListBox doesn't seem to know how to render that item - the text is unselectable until I switch tabs and come back. Sometimes this takes multiple tries. The scrollbar itself changes in size drastically because of virtualization - it doesn't know that the rest of the ListBox's items are much smaller, and so makes the scrollbar too big until you scroll to a section of text where the ListBoxItems are much smaller. Overall, the user experience degrades to a point that is unacceptable.

So my question is this: how can I fix this behavior? Is there a way to enforce a cutoff height, so that long strings are split into multiple ListBoxItems? Switching off virtualization is not an option, as virtualization is what gives me the performance I need to print tens of thousands of lines of text to my application without any slowdown.

Also, before anyone points me at "duplicate questions" that might answer this, I've already looked at Constraining item heights in WPF ListBox, with indicator - this was the only relevant question I could find, and doesn't answer my question (it simply caps the height, cutting of content, which is unacceptable).

0

There are 0 answers