ScrollViewer使用ItemsControl进行逻辑滚动 [英] Scrollviewer logical scrolling with itemscontrol

查看:237
本文介绍了ScrollViewer使用ItemsControl进行逻辑滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF应用程序中,我有一个ScrollViewer,其中有一个ItemsControl,其项目数据绑定到集合,并且有一个为项目指定的模板.我希望ScrollViewer使用逻辑滚动,因此设置ScrollViewer.CanContentScroll ="True"标志,并将ItemsControl的ItemsPanel模板设置为StackPanel.

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?

谢谢 汤姆

推荐答案

对不起,您的答复很晚... 这是Microsoft添加"到.Net 4.5(基于像素的滚动)的功能.

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

在WPF 4上,TreeView确实具有逻辑滚动,但是ListBox和ItemsControl没有. 那么,它如何在TreeView而不是ListBox上工作呢?因为滚动是由VirtualizingStackPanel管理的,所以应该问这个问题.

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.

好吧,秘密"位于VirtualizingStackPanel中名为IsPixelBased的内部属性中.

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

如果将其设置为true,则将进行逻辑回滚.

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

但是,这是有成本的.似乎对于大型Items Source(甚至具有Virtualization和Container Recycling),滚动速度很慢. (大型项目来源大约为50,000或100,000),而物理(基于项目)滚动则不是.

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.

我希望这个问题可以在WPF 4.5中解决

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);
    }
}

这篇关于ScrollViewer使用ItemsControl进行逻辑滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆