Home > Silverlight > Scrolling with ease

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

Categories: Silverlight Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.