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