コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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;
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        private static void OnVerticalScrollOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AnimatedScrollViewer thisSViewer = (AnimatedScrollViewer)d;

            thisSViewer.ScrollToVerticalOffset((double)e.NewValue);
        }
コード例 #8
0
        void VScrollBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            AnimatedScrollViewer thisScroller = this;
            ScrollBar            scrollbar    = (sender as ScrollBar);

            /*ScrollBar animationScrollbar;
             * if (scrollbar == _aniVerticalScrollBar)
             * {
             *  animationScrollbar = _animationVerticalScrollBar;
             * }
             * else
             * {
             *  //animationScrollbar = _animationHorizontalScrollBar;
             *  animationScrollbar = _animationVerticalScrollBar; //TEMP
             * }*/
            double oldTargetVOffset = (double)e.OldValue;
            double newTargetVOffset = (double)e.NewValue;

            if (newTargetVOffset != thisScroller.TargetVerticalOffset)
            {
                double deltaVOffset = Math.Round((newTargetVOffset - oldTargetVOffset), 3);

                if (deltaVOffset == 1)
                {
                    thisScroller.TargetVerticalOffset = oldTargetVOffset + thisScroller.ViewportHeight;
                }
                else if (deltaVOffset == -1)
                {
                    thisScroller.TargetVerticalOffset = oldTargetVOffset - thisScroller.ViewportHeight;
                }
                else if (deltaVOffset == 0.1)
                {
                    thisScroller.TargetVerticalOffset = oldTargetVOffset + 16.0;
                }
                else if (deltaVOffset == -0.1)
                {
                    thisScroller.TargetVerticalOffset = oldTargetVOffset - 16.0;
                }
                else
                {
                    thisScroller.TargetVerticalOffset = newTargetVOffset;
                }

                /*DoubleAnimation animation = new DoubleAnimation()
                 * {
                 *  From = 0,
                 *  To = newTargetVOffset,
                 *  Duration = ScrollingTime
                 * };
                 *
                 * animation.Completed += delegate
                 * {
                 *  animationScrollbar.BeginAnimation(ScrollBar.ValueProperty, null);
                 *  animationScrollbar.Visibility = Visibility.Hidden;
                 *  scrollbar.Visibility = Visibility.Visible;
                 * };
                 *
                 * scrollbar.Visibility = Visibility.Hidden;
                 * animationScrollbar.Visibility = Visibility.Visible;
                 * animationScrollbar.BeginAnimation(ScrollBar.ValueProperty, animation);*/
            }
        }