Question

I have the following XAML snippet:

<ItemsControl ItemsSource="..." ItemTemplate="..." VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" ScrollViewer.CanContentScroll="True">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel Orientation="Vertical" utils:VirtualizingStackPanelAttachedProperties.IsPixelBasedScrollingEnabled="True"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.Template>
        <ControlTemplate>
            <Border BorderThickness="..." Padding="..." BorderBrush="..." Background="..." SnapsToDevicePixels="True">
               <ScrollViewer Padding="..." Focusable="False">
                   <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
               </ScrollViewer>
            </Border>
        </ControlTemplate>
    </ItemsControl.Template>
</ItemsControl>

As you can see, I have ScrollViewer.CanContentScroll="True" and utils:VirtualizingStackPanelAttachedProperties.IsPixelBasedScrollingEnabled="True" (which is an attached property that sets IsPixelBased internal property to true, as suggested here).

This works as expected in Windows XP where the scrolling is fine-grained, pixel-based.
However, this does not work as expected in Windows 7 where the scrolling is still item-based, the same as in Windows XP when NOT setting the above mentioned attached property to True.
The only way I could get pixel-based scrolling working in Windows 7 was to set CanContentScroll to False, but this is turning off virtualization.

Any idea why this happens? Is it the case that somehow in Windows XP the virtualization is not really working although it is enabled?

Was it helpful?

Solution

Most likely that internal property is being set back to false. As is mentioned in that link in CLR 4.5 you would set the ScrollUnit to pixel. So maybe you have Clr 4.5 on that system and because that isn't being set to pixel the IsPixelBased is set back. You could alter that attached behavior to set the ScrollUnit if it exists.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top