Animating the scrolling in a ScrollViewer
seems to be a common task. I implemented it using a timer, similar to the approach found here. This method was working great, it was very smooth and looked perfect.
However, now that the complexity and number of objects contained within my ScrollViewer
has increased, the animation looks very jerky. I find this odd because it works fine if I scroll manually.
public void ShiftLeft(int speed = 11)
{
CustomTimer timer = new CustomTimer(); //DispatchTimer with "life"
timer.Interval = new TimeSpan(0, 0, 0, 0, 5);
timer.Tick += ((sender, e) =>
{
scrollViewer1.ScrollToHorizontalOffset(
scrollViewer1.HorizontalOffset - (scrollViewer1.ScrollableWidth / (gridColumnCount - 3) / speed));
if (scrollViewer1.HorizontalOffset == 0) //cant scroll any more
((CustomTimer)sender).Stop();
((CustomTimer)sender).life++;
if (((CustomTimer)sender).life >= speed) //reached destination
((CustomTimer)sender).Stop();
});
timer.Start();
}
Is there a problem with my approach that is causing this weird jerking? Any idea how to fix it?