2

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?

Community
  • 1
  • 1
Adi
  • 106
  • 1
  • 6

1 Answers1

2

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.

AndrewS
  • 6,054
  • 24
  • 31
  • Thank you for your answer Andrew, indeed that was the case, both the user that reported the issue and I had .NET Framework 4.5 installed on the Windows 7 machine. However, I tried to set ScrollUnit attached property to Pixel using reflection (the code needs to target 4.0), and that still didn't give me the expected result. Most likely there's more to it on 4.5, but I didn't get the chance to peek with Reflector yet. – Adi Jan 18 '13 at 04:57
  • 1
    Did you set the property on the itemscontrol or the panel? I think the panel checks the scrollunit attachedprooerty on the itemscontrol. Check the SetVirtualizationState method of virtstackpanel. It may also check the VirtalizationMode. – AndrewS Jan 18 '13 at 15:17