Scrolling with ease

This sample shows how to have animation while scrolling.

The UI is made up of a Grid with 3 columns with buttons for scrolling left and right and a listbox in the middle.

we are going to scroll horizontally 3 items at a time.
ListBox’s ItemsSource is set to a range of numbers 1-20

list1.ItemsSource = Enumerable.Range(1,20);

In the code we set up eventhandlers in page Loaded event along with a timer.
we have some variables to keep track of where we should stop scrolling. the most important variable is ‘easing’ which determines how fast or slow the animation will be. In the Timer_Tick event we change the horizontalOffset and when we reach the desired offset we stop scrolling

The code is not optimized and the values are hardcoded.
If there is another/better way of doing this sort of thing , please leave a comment

you can see a demo here and download source from here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s