问题描述
限时送ChatGPT账号..有没有办法检测ListView
的ScrollViwer
处于滚动模式并停止滚动.在 windows phone 8.1 ListView
中,我们无法获得滚动查看器的引用.
Is there a way to detect that ScrollViwer
of ListView
is in scrolling mode and stopped scrolling. In windows phone 8.1 ListView
we can not get reference of the scrollviewer.
有人在 Windows Phone 8.1 WinRT 应用程序中做过吗?
Any one done it in windows phone 8.1 WinRT app?
推荐答案
一旦 ListView Loaded
你可以像这样得到 ScrollViewer
:
Once the ListView is Loaded
you can get the ScrollViewer
like this:
var sv = (ScrollViewer)VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(this.ListV, 0), 0);
编辑
正如 Romasz 所建议的,一旦你获得了 ScrollViewer
,你就可以使用它的 ViewChanged
事件来监控它何时滚动和何时停止.
As Romasz suggested, once you get the ScrollViewer
, you can use its ViewChanged
event, to monitor when it is scrolling and when it stops.
此外,这是我用于遍历可视化树的通用扩展方法:
Also, here's the generic extension method that I use for traversing the visual tree:
// The method traverses the visual tree lazily, layer by layer
// and returns the objects of the desired type
public static IEnumerable<T> GetChildrenOfType<T>(this DependencyObject start) where T : class
{
var queue = new Queue<DependencyObject>();
queue.Enqueue(start);
while (queue.Count > 0) {
var item = queue.Dequeue();
var realItem = item as T;
if (realItem != null) {
yield return realItem;
}
int count = VisualTreeHelper.GetChildrenCount(item);
for (int i = 0; i < count; i++) {
queue.Enqueue(VisualTreeHelper.GetChild(item, i));
}
}
}
要使用此方法获取 ScrollViewer
,请执行以下操作:
To get the ScrollViewer
using this methos, do this:
var sv = yourListView.GetChildrenOfType<ScrollViewer>().First();
这篇关于如何检测 ListView 向上或向下滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论