1

In a WPF app I have a ScrollViewer, in which is an ItemsControl, the items of which are databound to a collection, and I have a template specified for the items. I want the ScrollViewer to use logical scrolling, so I set the ScrollViewer.CanContentScroll="True" flag, and set the ItemsPanel template of the ItemsControl to be a StackPanel.

However, the scrolling is still physical rather than logical. What am I doing wrong?

Thanks Tom

H.B.
  • 166,899
  • 29
  • 327
  • 400
Tom Davies
  • 2,386
  • 3
  • 27
  • 44
  • By "physical rather than logical", are you using "logical" to refer to UI Virtualization? If you, you might be interested in this question: [Virtualizing an ItemsControl](http://stackoverflow.com/q/2783845/302677) – Rachel Mar 02 '12 at 16:06

1 Answers1

0

Sorry for the late reply... This is something that Microsoft "added" to .Net 4.5 (Pixel based scrolling).

On WPF 4, TreeView does have a logical scrolling, but ListBox and ItemsControl doesn't. So how come it works on a TreeView and not on ListBox?? This is a question that should be asked since the scrolling is being managed by the VirtualizingStackPanel.

Well, the "secret" is in an internal property in VirtualizingStackPanel called IsPixelBased.

If you set it to true then you get the logical scrolling back.

However, this has a cost. It seems that with a large Items Source (even with Virtualization and Container Recycling) the scroll is sluggish. (large items source is like 50,000 or 100,000), while with physical (item based) scrolling it is not.

I hope that this issue is solved in WPF 4.5

Here is an example of having a virtualizing pabel with Pixel Based scrolling by default:

public class VSP : VirtualizingStackPanel
{
    public VSP()
    {
        typeof(VSP).GetProperty("IsPixelBased", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, true, null);
    }
}
Stephan
  • 41,764
  • 65
  • 238
  • 329
Saragani
  • 96
  • 7