Inheritance: EasingFunctionBase, IQuarticEase
Ejemplo n.º 1
0
        /// <summary>
        /// 更新所有子项位置
        /// </summary>
        private void GotoPreOrNext(bool toNext)
        {
            if (_storyboard != null && !_isStoryboardCompleted)
            {
                _storyboard?.Stop();
                ResetPosition();
            }

            _isStoryboardCompleted = false;
            var img0 = GetItemByTag(0);
            var img1 = GetItemByTag(1);
            var img2 = GetItemByTag(2);
            var img3 = GetItemByTag(3);

            var center = CanvasContainer.ActualWidth / 2;
            var duration = 600;
            var beginTime = 60;
            _storyboard = new Storyboard();
            var ease = new QuarticEase() { EasingMode = EasingMode.EaseOut };

            ViewerItem target0, target2;
            if (toNext)
            {
                target0 = img0;
                target2 = img2;
            }
            else
            {
                target0 = img2;
                target2 = img0;
            }

            // img0
            StoryboardHelper.CreatAnimation(target0, _storyboard, "UIElement.Opacity", 110, 0, 0, null, false);

            // img1
            var tanslateX = img1.ActualWidth * SIDE_DISTANCE_RATIO;

            double toValue = toNext ? -tanslateX : tanslateX;
            StoryboardHelper.CreatAnimation(img1.RenderTransform, _storyboard, "(CompositeTransform.TranslateX)", duration, 0, toValue, ease, false);
            StoryboardHelper.CreatAnimation(img1.RenderTransform, _storyboard, "(CompositeTransform.ScaleX)", duration, 0, SCALE_RATIO, ease, false);
            StoryboardHelper.CreatAnimation(img1.RenderTransform, _storyboard, "(CompositeTransform.ScaleY)", duration, 0, SCALE_RATIO, ease, false);

            // img2
            StoryboardHelper.CreatAnimation(target2.RenderTransform, _storyboard, "(CompositeTransform.TranslateX)", duration, beginTime, toValue, ease, false);
            StoryboardHelper.CreatAnimation(target2.RenderTransform, _storyboard, "(CompositeTransform.ScaleX)", duration, 0, 1, ease, false);
            StoryboardHelper.CreatAnimation(target2.RenderTransform, _storyboard, "(CompositeTransform.ScaleY)", duration, 0, 1, ease, false);

            // img3
            Canvas.SetLeft(img3, center - img3.ActualWidth / 2 + img3.ActualWidth * SIDE_DISTANCE_RATIO);
            var item = GetNextOrPreItem(target2, toNext);
            if (img3.DataContext != item)
            {
                img3.DataContext = item;
            }
            Canvas.SetLeft(img3, Canvas.GetLeft(target2));
            var trans = img3.RenderTransform as CompositeTransform;
            trans.ScaleX = SCALE_RATIO;
            trans.ScaleY = SCALE_RATIO;
            StoryboardHelper.CreatAnimation(img3, _storyboard, "UIElement.Opacity", duration, 0, 1, null, false);

            // zindex
            ObjectAnimationUsingKeyFrames oa1 = new ObjectAnimationUsingKeyFrames() {BeginTime = TimeSpan.FromMilliseconds(0)};
            oa1.KeyFrames.Add(new DiscreteObjectKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(0), Value = 0 });
            Storyboard.SetTargetProperty(oa1, "(Canvas.ZIndex)");
            Storyboard.SetTarget(oa1, img1);

            ObjectAnimationUsingKeyFrames oa2 = new ObjectAnimationUsingKeyFrames() {BeginTime = TimeSpan.FromMilliseconds(0)};
            oa2.KeyFrames.Add(new DiscreteObjectKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(0), Value = 1 });
            Storyboard.SetTargetProperty(oa2, "(Canvas.ZIndex)");
            Storyboard.SetTarget(oa2, target2);

            _storyboard.Children.Add(oa1);
            _storyboard.Children.Add(oa2);

            target0.ShowMask(true);
            target2.ShowMask(false);
            img1.ShowMask(true);
            img3.ShowMask(true);

            UpdateTag(toNext);
            _storyboard.Begin();
            _storyboard.Completed += (e1, e2) =>
            {
                _isStoryboardCompleted = true;
                ResetPosition();
            };

        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新所有子项位置
        /// </summary>
        private void GotoPreOrNext(bool toNext)
        {
            var img0 = GetItemByTag(0);
            var img1 = GetItemByTag(1);
            var img2 = GetItemByTag(2);
            var img3 = GetItemByTag(3);

            var center = CanvasContainer.ActualWidth / 2;
            var duration = 600;
            var beginTime = 80;
            Storyboard storyboard = new Storyboard();
            var ease = new QuarticEase(){EasingMode = EasingMode.EaseOut};

            // img0
            StoryboardHelper.CreatAnimation(img0, storyboard, "UIElement.Opacity", duration, 0, 0, null, false);

            // img1
            var tanslateX = img1.ActualWidth * SIDE_DISTANCE_RATIO;

            double toValue = toNext ? -tanslateX : tanslateX;
            StoryboardHelper.CreatAnimation(img1.RenderTransform, storyboard, "(CompositeTransform.TranslateX)", duration, 0, toValue, ease, false);
            StoryboardHelper.CreatAnimation(img1.RenderTransform, storyboard, "(CompositeTransform.ScaleX)", duration, 0, SCALE_RATIO, ease, false);
            StoryboardHelper.CreatAnimation(img1.RenderTransform, storyboard, "(CompositeTransform.ScaleY)", duration, 0, SCALE_RATIO, ease, false);

            // img2
            StoryboardHelper.CreatAnimation(img2.RenderTransform, storyboard, "(CompositeTransform.TranslateX)", duration, beginTime, toValue, ease, false);
            StoryboardHelper.CreatAnimation(img2.RenderTransform, storyboard, "(CompositeTransform.ScaleX)", duration, 0, 1, ease, false);
            StoryboardHelper.CreatAnimation(img2.RenderTransform, storyboard, "(CompositeTransform.ScaleY)", duration, 0, 1, ease, false);

            // img3
            Canvas.SetLeft(img3, center - img3.ActualWidth / 2 + img3.ActualWidth * SIDE_DISTANCE_RATIO);
            var item = GetNextOrPreItem(img2, toNext);
            if (img3.DataContext != item)
            {
                img3.DataContext = item;
            }
            var trans = img3.RenderTransform as CompositeTransform;
            trans.ScaleX = SCALE_RATIO;
            trans.ScaleY = SCALE_RATIO;
            StoryboardHelper.CreatAnimation(img3, storyboard, "UIElement.Opacity", duration, 0, 1, null, false);

            // zindex
            ObjectAnimationUsingKeyFrames oa1 = new ObjectAnimationUsingKeyFrames();
            oa1.KeyFrames.Add(new DiscreteObjectKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(0), Value = 0 });
            Storyboard.SetTargetProperty(oa1,"(Canvas.ZIndex)");
            Storyboard.SetTarget(oa1,img1);

            ObjectAnimationUsingKeyFrames oa2 = new ObjectAnimationUsingKeyFrames();
            oa2.KeyFrames.Add(new DiscreteObjectKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(0), Value = 1 });
            Storyboard.SetTargetProperty(oa2, "(Canvas.ZIndex)");
            Storyboard.SetTarget(oa2, img2);

            storyboard.Children.Add(oa1);
            storyboard.Children.Add(oa2);


            storyboard.Begin();
            storyboard.Completed += (e1, e2) =>
            {
                Debug.WriteLine("Completed");
                UpdateTag(toNext);
                ResetPosition();
            };
        }
Ejemplo n.º 3
0
 //Get Easing Function
 private EasingFunctionBase GetEasingFunction(Easing type)
 {
     EasingFunctionBase func = null;
     switch (type)
     {
         case Easing.EaseSineIn:
         case Easing.EaseSineOut:
         case Easing.EaseSineInOut:
             func = new SineEase();
             break;
         case Easing.EaseCircleIn:
         case Easing.EaseCircleOut:
         case Easing.EaseCircleInOut:
             func = new CircleEase();
             break;
         case Easing.EaseQuadraticIn:
         case Easing.EaseQuadraticOut:
         case Easing.EaseQuadraticInOut:
             func = new QuadraticEase();
             break;
         case Easing.EaseCubicIn:
         case Easing.EaseCubicOut:
         case Easing.EaseCubicInOut:
             func = new CubicEase();
             break;
         case Easing.EaseQuarticIn:
         case Easing.EaseQuarticOut:
         case Easing.EaseQuarticInOut:
             func = new QuarticEase();
             break;
         case Easing.EaseQuinticIn:
         case Easing.EaseQuinticOut:
         case Easing.EaseQuinticInOut:
             func = new QuinticEase();
             break;
         case Easing.EaseBackIn:
         case Easing.EaseBackOut:
         case Easing.EaseBackInOut:
             func = new BackEase();
             break;
         case Easing.EaseBounceIn:
         case Easing.EaseBounceOut:
         case Easing.EaseBounceInOut:
             func = new BounceEase();
             break;
         case Easing.EaseElasticIn:
         case Easing.EaseElasticOut:
         case Easing.EaseElasticInOut:
             func = new ElasticEase();
             break;
         case Easing.EaseExpoIn:
         case Easing.EaseExpoOut:
         case Easing.EaseExpoInOut:
             func = new ExponentialEase();
             break;
         case Easing.EasePowerIn:
         case Easing.EasePowerOut:
         case Easing.EasePowerInOut:
             func = new PowerEase();
             break;
         default:
             break;
     }
     if (func != null)
     {
         switch ((int)type % 3)
         {
             case 0:
                 func.EasingMode = EasingMode.EaseIn;
                 break;
             case 1:
                 func.EasingMode = EasingMode.EaseOut;
                 break;
             default:
                 func.EasingMode = EasingMode.EaseInOut;
                 break;
         }
     }
     return func;
 }