Tech Tock

Time is of the essence.

Another Thing about WPF Virtualization

Just a little follow-up to my virtualization post from the other day.  WPF virtualization works great. I had it working horizontally and vertically at the same time and with synchronized scrolling controls.

To do horizontal and vertical, just make a vertical items list and for each item, make it a horizontal list.  Works straight out of the box.


Make sure your virtualized control isn’t wrapped in a scrollbar.  Even if its 3 controls outside, if a scrollbar is giving unlimited space to an ItemsControl you want to virtualize, it won’t work. A virtualizing control needs to be width (or height for vertical) constrained. I’d also bet that virtualization in a Canvas without setting a width on your ItemsControl would fail for the same reason, it just goes on and on.

January 14, 2013 Posted by | Uncategorized | , | Leave a comment

Another way to Check WPF Virtualization

If you Snoop a virtualized control you’ll only see ItemsContainers for the displaying items and a few cached ones if you’ve scrolled.  So if you have a collection of hundreds of items and you only see a dozen containers with Snoop, its because its virtualizing.

Snoop, the WPF Spy Utility

January 11, 2013 Posted by | Uncategorized | , , | Leave a comment

WPF Virtualization–Finicky?

I’m making a fun new control for a lot of data and needed to use a Virtualizing ItemsControl. We already had one in the project.  It looked like the example and was obviously intended to virtualize the ItemsControl. Upon testing, of course it didn’t work.  It gave exactly linear performance.

Virtualizing Stack Panel?
  1. <ItemsControl
  2. VirtualizingStackPanel.IsVirtualizing=”True”
  3. ScrollViewer.CanContentScroll=”True”
  4. ItemsSource=”{Binding Path=AccountViews.Tables[0]}”>
  5. <ItemsControl.ItemTemplate>
  6. <DataTemplate>
  7. <TextBlock
  8. Initialized=”TextBlock_Initialized”
  9. Text=”{Binding Path=Name}” />
  10. </DataTemplate>
  11. </ItemsControl.ItemTemplate>
  12. <ItemsControl.ItemsPanel>
  13. <ItemsPanelTemplate>
  14. <VirtualizingStackPanel />
  15. </ItemsPanelTemplate>
  16. </ItemsControl.ItemsPanel>
  17. <ItemsControl.Template>
  18. <ControlTemplate>
  19. <Border
  20. BorderThickness=”{TemplateBinding Border.BorderThickness}
  21. Padding=”{TemplateBinding Control.Padding}
  22. BorderBrush=”{TemplateBinding Border.BorderBrush}
  23. Background=”{TemplateBinding Panel.Background}
  24. SnapsToDevicePixels=”True”>
  25. <ScrollViewer
  26. Padding=”{TemplateBinding Control.Padding}
  27. Focusable=”False”>
  28. <Grid>
  29. <ItemsPresenter
  30. SnapsToDevicePixels=”{TemplateBinding UIElement.SnapsToDevicePixels}” />
  31. </Grid>
  32. </ScrollViewer>
  33. </Border>
  34. </ControlTemplate>
  35. </ItemsControl.Template>
  36. </ItemsControl>

Here’s the offending lines:

Virtualizing Antagonist
  1.      <ScrollViewer
  2. Padding=”{TemplateBinding Control.Padding}
  3. Focusable=”False”>
  4.          <Grid>
  5.              <ItemsPresenter
  6.     SnapsToDevicePixels=”{TemplateBinding UIElement.SnapsToDevicePixels}” />
  7.          </Grid>
  8.      </ScrollViewer>


That Grid wrapping the ItemsPresnter stops virtualization. It really has no business being there, but still…

As for WPF Virtualization being finicky, if you use one of the Controls That Implement Performance Features, such as ListBox, you shouldn’t have a problem (until you change the template).  OTOH, there are arguments against that too…

December 14, 2012 Posted by | Uncategorized | , , , | Leave a comment