Пример #1
0
        public Chart()
        {
            DefaultStyleKey             = typeof(Chart);
            storyboard                  = new Storyboard();
            scrollStoryboard            = new Storyboard();
            scrollStoryboard.Completed += (e, c) =>
            {
                //容器滚动动画结束

                //发送通知
                OnAnimationLockEvent?.Invoke(this, false, 0);

                isScrollAnimationActive = false;
            };
            sineEase = new SineEase()
            {
                EasingMode = EasingMode.EaseInOut
            };
            scrollAnimation = new DoubleAnimation();
        }
Пример #2
0
        /// <summary>
        /// 容器滚动
        /// </summary>
        /// <param name="d">0左,1右</param>
        private void Scroll(int d)
        {
            if (ItemsScrollViewer != null &&
                ItemsScrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible &&
                !isScrollAnimationActive
                )
            {
                isScrollAnimationActive = IsAnimation;
                //取一个数据控件
                double LostWidth = 0;

                if (ItemContainer.Children.Count > 1)
                {
                    //取第二个,才有margin属性
                    ChartItem chartItem    = ItemContainer.Children[1] as ChartItem;
                    double    oneItemWidth = chartItem.ActualWidth + chartItem.Margin.Left;
                    //每屏最多多少个项目
                    double onePageMaxItemNum = ItemsScrollViewer.ActualWidth / oneItemWidth;
                    if ((int)onePageMaxItemNum != onePageMaxItemNum)
                    {
                        //带小数点,需要计算
                        LostWidth = oneItemWidth - double.Parse(("0." + onePageMaxItemNum.ToString().Split('.')[1])) * oneItemWidth - chartItem.Margin.Left;
                    }
                }

                //计算一屏滚动值
                double onePageScrollValue = ItemsScrollViewer.ActualWidth - LostWidth - 2;
                //滚动值
                double to;
                if (d == 0)
                {
                    //左滚
                    double leftScrollValue = ItemsScrollViewer.HorizontalOffset - onePageScrollValue;
                    to = leftScrollValue > 0 ? leftScrollValue : 0;
                }
                else
                {
                    //右滚
                    double rightScrollValue = ItemsScrollViewer.HorizontalOffset + onePageScrollValue;
                    to = rightScrollValue < ItemsScrollViewer.ScrollableWidth ? rightScrollValue : ItemsScrollViewer.ScrollableWidth;
                }

                if (ItemsScrollViewer.HorizontalOffset == to)
                {
                    //不执行无变化的动画
                    isScrollAnimationActive = false;
                    return;
                }
                if (IsAnimation)
                {
                    OnAnimationLockEvent?.Invoke(this, true, 0);
                    scrollAnimation.From = ItemsScrollViewer.HorizontalOffset;
                    scrollAnimation.To   = to;
                    scrollStoryboard.Begin();
                }
                else
                {
                    ItemsScrollViewer.ScrollToHorizontalOffset(to);
                    HandleScrollViewerState();
                }
            }
        }