private static void PerformAutoPan(object sender, RoutedPanEventArgs e) { var element = sender as FrameworkElement; var scrollViewer = GetScrollViewer(element); if (scrollViewer == null) { throw new InvalidOperationException("Could not resolve scroll viewer from registered framework element."); } var handler = GetVelocityScroller(element); if (handler == null) { handler = new VelocityScroller(scrollViewer); SetVelocityScroller(element, handler); } // Update velocity. handler.Velocity = new Vector(e.VelocityX, e.VelocityY); }