void HScrollBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { AnimatedScrollViewer thisScroller = this; double oldTargetHOffset = (double)e.OldValue; double newTargetHOffset = (double)e.NewValue; if (newTargetHOffset != thisScroller.TargetHorizontalOffset) { double deltaVOffset = Math.Round((newTargetHOffset - oldTargetHOffset), 3); if (deltaVOffset == 1) { thisScroller.TargetHorizontalOffset = oldTargetHOffset + thisScroller.ViewportWidth; } else if (deltaVOffset == -1) { thisScroller.TargetHorizontalOffset = oldTargetHOffset - thisScroller.ViewportWidth; } else if (deltaVOffset == 0.1) { thisScroller.TargetHorizontalOffset = oldTargetHOffset + 16.0; } else if (deltaVOffset == -0.1) { thisScroller.TargetHorizontalOffset = oldTargetHOffset - 16.0; } else { thisScroller.TargetHorizontalOffset = newTargetHOffset; } } }
void AnimatedScrollViewer_PreviewKeyDown(object sender, KeyEventArgs e) { AnimatedScrollViewer thisScroller = (AnimatedScrollViewer)sender; if (thisScroller.CanKeyboardScroll) { Key keyPressed = e.Key; double newVerticalPos = thisScroller.TargetVerticalOffset; double newHorizontalPos = thisScroller.TargetHorizontalOffset; bool isKeyHandled = false; //Vertical Key Strokes code if (keyPressed == Key.Down) { newVerticalPos = NormalizeScrollPos(thisScroller, (newVerticalPos + 16.0), Orientation.Vertical); isKeyHandled = true; } else if (keyPressed == Key.PageDown) { newVerticalPos = NormalizeScrollPos(thisScroller, (newVerticalPos + thisScroller.ViewportHeight), Orientation.Vertical); isKeyHandled = true; } else if (keyPressed == Key.Up) { newVerticalPos = NormalizeScrollPos(thisScroller, (newVerticalPos - 16.0), Orientation.Vertical); isKeyHandled = true; } else if (keyPressed == Key.PageUp) { newVerticalPos = NormalizeScrollPos(thisScroller, (newVerticalPos - thisScroller.ViewportHeight), Orientation.Vertical); isKeyHandled = true; } if (newVerticalPos != thisScroller.TargetVerticalOffset) { thisScroller.TargetVerticalOffset = newVerticalPos; } //Horizontal Key Strokes Code if (keyPressed == Key.Right) { newHorizontalPos = NormalizeScrollPos(thisScroller, (newHorizontalPos + 16), Orientation.Horizontal); isKeyHandled = true; } else if (keyPressed == Key.Left) { newHorizontalPos = NormalizeScrollPos(thisScroller, (newHorizontalPos - 16), Orientation.Horizontal); isKeyHandled = true; } if (newHorizontalPos != thisScroller.TargetHorizontalOffset) { thisScroller.TargetHorizontalOffset = newHorizontalPos; } e.Handled = isKeyHandled; } }
private static void OnTargetHorizontalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AnimatedScrollViewer thisScroller = (AnimatedScrollViewer)d; if ((double)e.NewValue != thisScroller._aniHorizontalScrollBar.Value) { thisScroller._aniHorizontalScrollBar.Value = (double)e.NewValue; } thisScroller.animateScroller(thisScroller); }
private double NormalizeScrollPos(AnimatedScrollViewer thisScroll, double scrollChange, Orientation o) { double returnValue = scrollChange; if (scrollChange < 0) { returnValue = 0; } if (o == Orientation.Vertical && scrollChange > thisScroll.ScrollableHeight) { returnValue = thisScroll.ScrollableHeight; } else if (o == Orientation.Horizontal && scrollChange > thisScroll.ScrollableWidth) { returnValue = thisScroll.ScrollableWidth; } return(returnValue); }
void CustomPreviewMouseWheel(object sender, MouseWheelEventArgs e) { double mouseWheelChange = (double)e.Delta; AnimatedScrollViewer thisScroller = (AnimatedScrollViewer)sender; double newVOffset = thisScroller.TargetVerticalOffset - (mouseWheelChange / 3); if (newVOffset < 0) { thisScroller.TargetVerticalOffset = 0; } else if (newVOffset > thisScroller.ScrollableHeight) { thisScroller.TargetVerticalOffset = thisScroller.ScrollableHeight; } else { thisScroller.TargetVerticalOffset = newVOffset; } e.Handled = true; }
private void animateScroller(object objectToScroll) { AnimatedScrollViewer thisScrollViewer = objectToScroll as AnimatedScrollViewer; Duration targetTime = new Duration(thisScrollViewer.ScrollingTime); KeyTime targetKeyTime = thisScrollViewer.ScrollingTime; KeySpline targetKeySpline = thisScrollViewer.ScrollingSpline; DoubleAnimationUsingKeyFrames animateHScrollKeyFramed = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames animateVScrollKeyFramed = new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame HScrollKey1 = new SplineDoubleKeyFrame(thisScrollViewer.TargetHorizontalOffset, targetKeyTime, targetKeySpline); SplineDoubleKeyFrame VScrollKey1 = new SplineDoubleKeyFrame(thisScrollViewer.TargetVerticalOffset, targetKeyTime, targetKeySpline); animateHScrollKeyFramed.KeyFrames.Add(HScrollKey1); animateVScrollKeyFramed.KeyFrames.Add(VScrollKey1); thisScrollViewer.BeginAnimation(HorizontalScrollOffsetProperty, animateHScrollKeyFramed); thisScrollViewer.BeginAnimation(VerticalScrollOffsetProperty, animateVScrollKeyFramed); CommandBindingCollection testCollection = thisScrollViewer.CommandBindings; int blah = testCollection.Count; }
private static void OnVerticalScrollOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AnimatedScrollViewer thisSViewer = (AnimatedScrollViewer)d; thisSViewer.ScrollToVerticalOffset((double)e.NewValue); }