views:

56

answers:

2

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

+3  A: 

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.

Philip Rieck
@Philip - Thanks for the prompt reply. I have the VirtualizingStackPanel within a ListView. I am not using data grouping. I will edit my post with a sample XAML. I think I was not too clear in my post, what I was also wondering was how these WPF controls such as ScrollViewer/VirtualizingStackPanel work from within and why the various combination of these controls suppress certain behavior.
sc_ray
+1  A: 

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.

Nir
@Nir - Thanks. I have tried removing the ScrollViewer and the load time is faster but the built in Scrolling of the ListView does not scroll through all the elements in the dataset. The elements that are overflowing from the screen are no longer scrollable. Is the ListView ScrollViewer equipped to work with massive datasets?
sc_ray
@sc_ray - ListView is a little strange, so I'm really not sure, I've wrote a vitualizing panel and used it with ItemsControl and ListBox - so I know what's going on there. If you have massive datasets maybe you need to use DataGrid (part of WPF 4 and WPF Toolkit for 3.5 http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-datagrid-feature-walkthrough.aspx ) - I've never used DataGrid myself but this is exactly the scenario it was created for
Nir
@Nir - DataGrid does seem like an option. What makes this thing a little tricky is that each of these EmployeeAccounts are complex objects themselves. I have to figure out a way to load(or lazy load) 250 of these upon application startup. I will try to explore datagrid. It would have been helpful if there were any success stories using the Datagrid in a similar context.
sc_ray