Tech Tock

Time is of the essence.

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…

Advertisements

December 14, 2012 - Posted by | Uncategorized | , , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: