Reputation: 53
I'm currently building a Windows Phone 8 application with a scrollviewer that has some content in it. I want the scrollviewer to automatically scroll to either the bottom or the top when the user scrolling has finished.
The user should be able to scroll the Content up and down as he/she likes but when he/she finishes it should scroll to the bottom or top depending on what is closer. Maybe this image will help explain what i mean:
i tried overwriting the MouseLeave event but the result is erratic and not really smooth:
private void mainScrollViewer_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
//Scrollviewer dazu brigen, jeweils zum einen oder anderen ende der Ansicht zu springen, aber nicht mittendrin stehen zu bleiben
if (mainScrollViewer.VerticalOffset > (ContentPanel.ActualHeight/2))
{
mainScrollViewer.ScrollToVerticalOffset(mainScrollViewer.ActualHeight);
}
else
{
mainScrollViewer.ScrollToVerticalOffset(0);
}
}
Am i missing something here? Is there an easy way to do it? and if not... whats the best way to do this?
Thanks for your help i really appreciate it!
Upvotes: 1
Views: 322
Reputation: 65556
No, there's not an easy way to do something like this.
As ScrollToVerticalOffset
doesn't animate smoothly, your best bet is a custom control to do this for you. For an example see http://sviluppomobile.blogspot.co.uk/2013/04/smooth-scrolling-content-on-windows.html
Upvotes: 1