虚拟化面板中基于WPF 4.0像素的滚动

虚拟化面板中基于WPF 4.0像素的滚动,wpf,ui-virtualization,Wpf,Ui Virtualization,我有以下XAML片段: <ItemsControl ItemsSource="..." ItemTemplate="..." VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" ScrollViewer.CanContentScroll="True"> <ItemsControl.ItemsPanel> &

我有以下XAML片段:

<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>

如您所见,我有ScrollViewer.CanContentScroll=“True”和utils:VirtualzingStackPanelAttachedProperties.IsPixelBasedScrollingEnabled=“True”(这是一个附加属性,按照建议将基于ispixelbase的内部属性设置为True)。

这与Windows XP中的预期一样,在Windows XP中,滚动是细粒度的、基于像素的。
但是,在Windows 7中,滚动仍然是基于项目的,这与在Windows XP中没有将上述附加属性设置为True时的情况相同。在Windows 7中,这与预期不一样。
我在Windows7中实现基于像素的滚动的唯一方法是将CanContentScroll设置为False,但这将关闭虚拟化。


知道为什么会这样吗?是不是在Windows XP中,虚拟化虽然已启用,但却无法真正工作

内部属性很可能被设置回false。如CLR 4.5中的链接所述,您可以将ScrollUnit设置为像素。因此,可能您在该系统上安装了Clr 4.5,因为它没有设置为像素,所以iPixelbased被设置为后退。您可以更改附加的行为以设置ScrollUnit(如果存在)

感谢您的回答Andrew,事实的确如此,报告问题的用户和我都在Windows 7计算机上安装了.NET Framework 4.5。但是,我尝试使用反射将ScrollUnit attached属性设置为Pixel(代码需要以4.0为目标),但仍然没有得到预期的结果。最有可能的是4.5版本中还有更多内容,但我还没有机会用Reflector偷看。您是否在itemscontrol或panel上设置了属性?我想面板会检查Items控件上的scrollunit AttachedProerty。检查virtstackpanel的SetVirtualizationState方法。它还可以检查虚拟化模式。