Ajeet
Ajeet

Reputation: 892

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

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.

Upvotes: 1

Views: 4114

Answers (2)

Shawn Kendrot
Shawn Kendrot

Reputation: 12465

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.

Upvotes: 2

Mr.kto
Mr.kto

Reputation: 76

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

Upvotes: 2

Related Questions