How to listen to the scrolling event of scrollviewer in windows phone 8?

大憨熊 提交于 2020-01-06 04:18:45

问题


I have developed for windows 8/8.1. Its scrollviewer generates events while scrolling like - ViewChanging/ViewChanged.

I couldn't find any such event for scrollviewer in windows phone 8. How can i listen to when the scrollviewer is scrolling in WP8?

I am trying to look for method similar to -ScrollViewDidScroll() of iOS development.


回答1:


Have tried to use this event? - ScrollViewer.ViewChanged event




回答2:


If you are using a ScrollViewer, or a ListBox you can listen to the LayoutUpdated event of the control and check the VerticalOffset. This is not ideal and is not updated as often as you would like, but will get you most of the way.

Here is an example using just a ScrollViewer

<ScrollViewer LayoutUpdated="OnScrollViewerUpdated">
    <TextBlock/>
    <TextBlock/>
    <TextBlock/>
    <TextBlock/>
    <TextBlock/>
</ScrollViewer>

Code:

private void OnScrollViewerUpdated(object sender, EventArgs e)
{
    var scrollViewer = (ScrollViewer) sender;

    // do something with scrollViewer.VerticalOffset;
}

IF you are working with a LongListSelector from WP8, you can get updates immediately. You can hook into the ViewportControlof the LLS and get it's ViewPort location. Here is a blog post detailing how you could accomplish this.



来源:https://stackoverflow.com/questions/21634708/how-to-listen-to-the-scrolling-event-of-scrollviewer-in-windows-phone-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!