Exemplo n.º 1
0
        public static void ScrollSkip(this ItemsControl listbox, int count)
        {
            ScrollViewer scrollHost = VisualTreeHelper.GetChild(listbox, 0) as ScrollViewer;

            for (DependencyObject obj2 = listbox; obj2 != null; obj2 = VisualTreeHelper.GetChild(obj2, 0))
            {
                ScrollViewer viewer = obj2 as ScrollViewer;
                if (viewer != null)
                {
                    scrollHost = viewer;
                    break;
                }
            }
            if (scrollHost != null && scrollHost.IsLoaded)
            {
                double fromHorizontalOffset = scrollHost.HorizontalOffset;
                double toHorizontalOffset   = 0.0;
                double fromVerticalOffset   = scrollHost.VerticalOffset;
                double toVerticalOffset     = 0.0;
                toHorizontalOffset = (scrollHost.ExtentWidth / listbox.Items.Count) * count + fromHorizontalOffset;
                toVerticalOffset   = (scrollHost.ExtentHeight / listbox.Items.Count) * count + fromVerticalOffset;

                if (ScrollViewer.GetHorizontalScrollBarVisibility(listbox) != ScrollBarVisibility.Disabled)
                {
                    DoubleAnimation animation = new DoubleAnimation(fromHorizontalOffset, toHorizontalOffset, new TimeSpan(0, 0, 0, 0, 800), FillBehavior.HoldEnd);
                    scrollHost.BeginAnimation(ItemControlExtentionMethods.HorizontalOffsetProperty, animation);
                }
                if (ScrollViewer.GetVerticalScrollBarVisibility(listbox) != ScrollBarVisibility.Disabled)
                {
                    DoubleAnimation animation = new DoubleAnimation(fromVerticalOffset, toVerticalOffset, new TimeSpan(0, 0, 0, 0, 800), FillBehavior.HoldEnd);
                    scrollHost.BeginAnimation(ItemControlExtentionMethods.VerticalOffsetProperty, animation);
                }
            }
        }
Exemplo n.º 2
0
        private static void AnimateScroll(ScrollViewer scrollViewer, double ToValue)
        {
            scrollViewer.BeginAnimation(VerticalOffsetProperty, null);
            DoubleAnimation verticalAnimation = new DoubleAnimation();

            verticalAnimation.From     = scrollViewer.VerticalOffset;
            verticalAnimation.To       = ToValue;
            verticalAnimation.Duration = new Duration(GetTimeDuration(scrollViewer));
            scrollViewer.BeginAnimation(VerticalOffsetProperty, verticalAnimation);
        }
Exemplo n.º 3
0
        private void BeginScrollViewerAnimation(double animationOffset)
        {
            EasingFunctionBase easeFunction = new CubicEase
            {
                EasingMode = EasingMode.EaseOut
            };
            var doubleAnimation = new DoubleAnimation
            {
                Duration       = new Duration(TimeSpan.FromSeconds(0.6)),
                EasingFunction = easeFunction
            };

            recordAnimationOffset = recordAnimationOffset + animationOffset;
            if (recordAnimationOffset > PART_ScrollViewer.ExtentHeight
                ||
                recordAnimationOffset < 0)
            {
                recordAnimationOffset = recordAnimationOffset - animationOffset;
                return;
            }

            doubleAnimation.To         = recordAnimationOffset;
            doubleAnimation.Completed += DoubleAnimation_Completed;

            PART_ScrollViewer.BeginAnimation(ScrollViewerBehavior.VerticalOffsetProperty, doubleAnimation);
            PART_ScrollViewer.ScrollToVerticalOffset(PART_ScrollViewer.VerticalOffset + recordAnimationOffset);
        }
        public static void ScrollToOffset(ScrollViewer scrollViewer, Orientation orientation, double offset, double duration = 500, IEasingFunction easingFunction = null)
        {
            var animation = new DoubleAnimation(offset, TimeSpan.FromMilliseconds(duration));

            easingFunction ??= new CubicEase
            {
                EasingMode = EasingMode.EaseOut
            };
            animation.EasingFunction = easingFunction;
            animation.FillBehavior   = FillBehavior.Stop;
            animation.Completed     += (s, e1) =>
            {
                if (orientation == Orientation.Vertical)
                {
                    SetCurrentVerticalOffset(scrollViewer, offset);
                }
                else
                {
                    SetCurrentHorizontalOffset(scrollViewer, offset);
                }
                SetIsAnimating(scrollViewer, false);
            };
            SetIsAnimating(scrollViewer, true);

            scrollViewer.BeginAnimation(orientation == Orientation.Vertical ? CurrentVerticalOffsetProperty : CurrentHorizontalOffsetProperty, animation, HandoffBehavior.Compose);
        }
Exemplo n.º 5
0
        public static void ScrollToSelectedItem(this ItemsControl listbox, object selectedItem)
        {
            ScrollViewer scrollHost = VisualTreeHelper.GetChild(listbox, 0) as ScrollViewer;

            for (DependencyObject obj2 = listbox; obj2 != null; obj2 = VisualTreeHelper.GetChild(obj2, 0))
            {
                ScrollViewer viewer = obj2 as ScrollViewer;
                if (viewer != null)
                {
                    scrollHost = viewer;
                    break;
                }
            }
            if (scrollHost != null && scrollHost.IsLoaded)
            {
                double fromValue = scrollHost.HorizontalOffset;
                double toValue   = 0.0;
                if (selectedItem != null)
                {
                    FrameworkElement visual = listbox.ItemContainerGenerator.ContainerFromItem(selectedItem) as FrameworkElement;
                    if (visual != null)
                    {
                        Vector vector = VisualTreeHelper.GetOffset(visual);
                        toValue = (visual.ActualWidth - scrollHost.ViewportWidth) / 2 + vector.X;
                    }
                }
                DoubleAnimation animation = new DoubleAnimation(fromValue, toValue, new TimeSpan(0, 0, 0, 0, 500), FillBehavior.HoldEnd);
                scrollHost.BeginAnimation(ItemControlExtentionMethods.HorizontalOffsetProperty, animation);
            }
        }
        static void OnAnimatedVerticalOffsetChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            ScrollViewer scrollViewer = target as ScrollViewer;

            double difference = ((double)e.NewValue - (double)e.OldValue);
            //Debug.WriteLine("Scroll animation difference: " + difference);

            /*double toVal = Math.Max(scrollViewer.VerticalOffset + difference, GetPointsToScroll(scrollViewer));
             *
             * if (difference < 0)
             *  toVal = Math.Min(scrollViewer.VerticalOffset + difference, -GetPointsToScroll(scrollViewer));
             *
             * if (toVal < 0)
             *  toVal = 0;
             * else if (toVal > scrollViewer.ScrollableHeight)
             *  toVal = scrollViewer.ScrollableHeight;*/

            DoubleAnimation verticalAnimation = new DoubleAnimation()
            {
                From           = scrollViewer.VerticalOffset,
                To             = (double)e.NewValue,//scrollViewer.VerticalOffset + difference, //toVal,
                EasingFunction = GetEasingFunction(scrollViewer),
                Duration       = new Duration(GetTimeDuration(scrollViewer))
            };

            scrollViewer.BeginAnimation(VerticalOffsetProperty, verticalAnimation);
        }
Exemplo n.º 7
0
        public void GridUp(Grid grid, ScrollViewer scrollViewer, Rectangle border)
        {
            Thickness from = new Thickness();

            from.Bottom = 314;
            from.Right  = 28;
            Thickness to = new Thickness();

            to.Bottom = 19;
            to.Right  = 28;
            ThicknessAnimation downAnimation = new ThicknessAnimation();

            downAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));
            downAnimation.From     = from;
            downAnimation.To       = to;
            grid.BeginAnimation(Grid.MarginProperty, downAnimation);
            Thickness from2 = new Thickness();

            from2.Bottom = 100;
            Thickness to2 = new Thickness();

            to2.Bottom         = 11;
            downAnimation.From = from2;
            downAnimation.To   = to2;
            scrollViewer.BeginAnimation(ScrollViewer.MarginProperty, downAnimation);
            border.BeginAnimation(Border.MarginProperty, downAnimation);

            scrollViewer.Visibility = Visibility.Visible;
            border.Visibility       = Visibility.Visible;
        }
Exemplo n.º 8
0
        private static void AnimateScroll(ScrollViewer scrollViewer, double ToValue)
        {
            scrollViewer.BeginAnimation(ScrollAnimationBehavior.VerticalOffsetProperty, null);
            DoubleAnimation verticalAnimation = new DoubleAnimation
            {
                From           = scrollViewer.VerticalOffset,
                To             = ToValue,
                Duration       = TimeSpan.FromSeconds(0.7),
                EasingFunction = new ExponentialEase
                {
                    EasingMode = EasingMode.EaseOut,
                    Exponent   = 1.2
                }
            };

            scrollViewer.BeginAnimation(ScrollAnimationBehavior.VerticalOffsetProperty, verticalAnimation);
        }
Exemplo n.º 9
0
        public void chooselistmoveoin(ScrollViewer sc)
        {
            ThicknessAnimation anim2 = new ThicknessAnimation();

            anim2.From     = new Thickness(0, 0, 0, 0);
            anim2.To       = new Thickness(315, 0, 0, 0);
            anim2.Duration = TimeSpan.FromSeconds(0.36);
            sc.BeginAnimation(MarginProperty, anim2);
        }
Exemplo n.º 10
0
        public static void AnimateScrollviewer(ScrollViewer scroll, System.Windows.Thickness toThickness)
        {
            ThicknessAnimation animation = new ThicknessAnimation()
            {
                AccelerationRatio = .9,
                Duration          = TimeSpan.FromSeconds(.3),
                To = toThickness
            };

            scroll.BeginAnimation(ScrollViewer.MarginProperty, animation);
        }
Exemplo n.º 11
0
        private static void ScrollToVerticalOffsetInternal(ScrollViewer scrollViewer, double offset)
        {
            var animation = new DoubleAnimation(offset, TimeSpan.FromMilliseconds(500));

            animation.EasingFunction = new CubicEase
            {
                EasingMode = EasingMode.EaseOut
            };
            animation.FillBehavior = FillBehavior.Stop;
            animation.Completed   += (s, e1) =>
            {
                SetCurrentVerticalOffset(scrollViewer, offset);
                SetIsAnimating(scrollViewer, false);
            };
            SetIsAnimating(scrollViewer, true);

            scrollViewer.BeginAnimation(CurrentVerticalOffsetProperty, animation, HandoffBehavior.Compose);
        }
Exemplo n.º 12
0
        public void GridDown(Grid grid, ScrollViewer scrollViewer, Rectangle border)
        {
            Thickness from = new Thickness();

            from.Bottom = 314;
            from.Right  = 28;
            Thickness to = new Thickness();

            to.Bottom = 19;
            to.Right  = 28;
            ThicknessAnimation downAnimation       = new ThicknessAnimation();
            ThicknessAnimation downAnimationScroll = new ThicknessAnimation();

            Thickness top = new Thickness();

            to.Bottom = 29;
            to.Right  = 28;
            ThicknessAnimationUsingKeyFrames jumpAnimation = new ThicknessAnimationUsingKeyFrames();

            downAnimation.Completed += new EventHandler((o, ex) =>
            {
                scrollViewer.Visibility = Visibility.Hidden;
                border.Visibility       = Visibility.Hidden;
            });

            downAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));
            downAnimation.From     = to;
            downAnimation.To       = from;
            grid.BeginAnimation(Grid.MarginProperty, downAnimation);
            Thickness from2 = new Thickness();

            from2.Bottom = 100;
            Thickness to2 = new Thickness();

            to2.Bottom         = 11;
            downAnimation.From = to2;
            downAnimation.To   = from2;
            scrollViewer.BeginAnimation(ScrollViewer.MarginProperty, downAnimation);
            border.BeginAnimation(Border.MarginProperty, downAnimation);
        }