Reputation: 75150
I have a ScrollViewer
containing a StackPanel
that is filled with over 1000 items that each contain a bunch of other items. It performs like a champ at idle or when I actually scroll it. However, when I resize it or anything that causes it to resize (e.g. the containing top-level window), it gets really slow, freezes, and takes about 30 seconds to unfreeze and be resized.
I have discovered that setting VerticalScrollBarVisibility
to ScrollBarVisibility.Hidden
or ScrollBarVisibility.Disabled
before I resize makes it perfectly smooth. However, enabling and disabling ScrollBarVisibility
takes around 5 seconds each, which, while better than waiting 30 seconds to resize, is still too long a wait.
What can I do to help gain performance in resizing a StackPanel
in a ScrollPanel
that contains many items?
Upvotes: 3
Views: 663
Reputation: 21751
You might consider switching to a listbox (I know, sounds weird, but hear me out). The listbox uses a virtualizing stackpanel -- it manages how many controls are actually in memory, creating them as you scroll.
You can use a datatemplate to make each listbox item look like anything that you want.
(note, this is all assuming that you are displaying some sort of repeating data).
Upvotes: 1