我有以下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:VirtualizingStackPanelAttachedProperties.IsPixelBasedScrollingEnabled="True”(这是一个附加属性,将IsPixelBased内部属性设置为true,建议使用here)。
在Windows XP中,滚动是细粒度的、基于像素的,这与预期的一样。
但是,这在Windows 7中不能像预期的那样工作,在Windows 7中,滚动仍然是基于项目的,这与Windows XP中未将上述附加属性设置为True时的情况相同。
让基于像素的滚动在Windows7中工作的唯一方法是将CanContentScroll设置为False,但这会关闭虚拟化。
知道为什么会这样吗?是不是因为某种原因,在Windows XP中,虽然启用了虚拟化,但它并不能真正工作?
发布于 2013-01-16 10:24:41
最有可能的情况是内部属性被重新设置为false。正如CLR4.5中的链接中所提到的,您可以将ScrollUnit设置为像素。所以你可能在系统上安装了Clr4.5,因为它没有被设置为像素,所以IsPixelBased被设置回原来的位置。您可以更改附加的行为来设置ScrollUnit (如果它存在)。
https://stackoverflow.com/questions/14349848
复制相似问题