AnaghSharma
AnaghSharma

Reputation: 414

ScrollViewer events for Windows Phone 8

I have got a listbox. And the listbox items can be images, text, audio,video etc. The Items are fetched using Internet and sometimes the list becomes too long. I want to implement a "Go To Top" feature in my listbox which are used in many websites. As soon as the users start scrolling, a button appears which takes them to the top, and if they scroll back to the top, the button disappears.

The problem is I do not know what to do. If I disable the scrollviewer of my listbox and put the listbox inside a scrollviewer, then I do not know which of the scrollviewer's events and properties should I use?

Upvotes: 0

Views: 239

Answers (2)

SonofNun
SonofNun

Reputation: 467

You could use the ScrollStateChanged event on the RadDataboundListBox to see if the listbox is being scrolled. If it is, you can then show your ScrollToTop button.

Something like this:

private void RadDataBoundListBox_ScrollStateChanged(object sender, ScrollStateChangedEventArgs e)
{
    if (e.NewState == ScrollState.Scrolling)
    {
        // Code to show the ScrollToTop button
    }
}

You could play around with the different ScrollStates to show and hide the ScrollToTop button at different times. (i.e. when NewState == ScrollState.TopStretch, you could hide the button.)

If you are binding to the ItemsSource of the ListBox, you can use the BringIntoView method as mentioned above.

RadDataBoundListBox.BringIntoView(BoundObservableCollection[0]);

I hope this helps. Thanks, Joshua

Upvotes: 1

akshay2000
akshay2000

Reputation: 824

I'm really not sure why you are using RadDataBoundListBox (maybe you need the virtualization), but here are some useful members. Whole list can be found here.

TopVisibleItem: This property gets the top vieport item currently realized. This item can be used to find the index till which user has scrolled. So, if the index is say 25, you might want to show the 'Scroll to top' button.
BringIntoView: This method can be used on click event of the 'Scroll to top' button. Just pass the item at index 0 as a parameter.

Hope this solves it.

Upvotes: 0

Related Questions