Reputation: 8043
There seems to be a performance degradation when an items collection control is decorated with a ScrollViewer. In the particular application I am working on, there seems to be a big hit to the application when I decorate a VirtualizingStackPanel with a ScrollViewer. I am trying to load up 250 items in this particular container with the hopes that the user can scroll through all 250 of them. Can somebody shed some light on the internals of ScrollViewer and why its inclusion can slow down the initial load of the application?
<ScrollViewer
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
Visibility= "Visible">
<ListView ItemsSource="{Binding EmployeeAccounts}">
<ListView.ItemsPanel >
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</ScrollViewer>
Thanks
Upvotes: 2
Views: 6408
Reputation: 29614
Your problem is that in order to know what items are really on screen VirutalizingStackPanel has to interact with the ScrollViewer, this only works if the VirtualizingStackPanel and the ScrollViewer are inside the same control.
That is why this works if you use the ListView built in scrolling (the panel and ScrollViewer are both inside the same control) but this doesn't work if you wrap the ListView with a ScrollViewer (the panel is inside the control, the ScrollViewer is outside).
Putting the ListView (or any other ItemsControl) inside a ScrollViewer cancels virtualization.
Upvotes: 2
Reputation: 32578
First thing: are you trying to use smooth scrolling? If so, you're disabling the virtualization and you'll need to use item-by-item scrolling (CanContentScroll=true).
Also, are you using this in an itemscontrol? If not, you'll need to roll your own, as VirtualizingStackPanel works with the itemscontrol hosting it.
And lastly, are you using data grouping ? If so, you're out of luck again.
Other than these three things, using a virtualizingstackpanel inside an items control should have no problems scrolling. Note there is a difference between UI Virtualization and Data Virtualization though - check out those two entries from Bea Stollnitz's blog for some great info.
Upvotes: 6