An animation that interpolates a double-typed property from one value to another.
상속: TweenAnimation
예제 #1
0
        /// <internalonly />
        protected override ProceduralAnimation CreateTransitionAnimation(Panel container, EffectDirection direction)
        {
            if (_scaleTransform == null) {
                _scaleTransform = new ScaleTransform();
                container.RenderTransform = _scaleTransform;

                container.RenderTransformOrigin = new Point(0.5, 0.5);
            }

            TweenInterpolation interpolation = GetEffectiveInterpolation();
            TimeSpan shortDuration = TimeSpan.FromMilliseconds(Duration.TotalMilliseconds / 3);

            FlipScaleAnimation scaleAnimation =
                new FlipScaleAnimation(Duration, _scaleTransform,
                                       (direction == EffectDirection.Forward ? 180 : -180));
            scaleAnimation.Interpolation = interpolation;

            DoubleAnimation frontAnimation =
                new DoubleAnimation(container.Children[1], UIElement.OpacityProperty, shortDuration,
                                    (direction == EffectDirection.Forward ? 0 : 1));
            frontAnimation.Interpolation = interpolation;
            frontAnimation.StartDelay = shortDuration;

            DoubleAnimation backAnimation =
                new DoubleAnimation(container.Children[0], UIElement.OpacityProperty, shortDuration,
                                    (direction == EffectDirection.Forward ? 1 : 0));
            backAnimation.Interpolation = interpolation;
            backAnimation.StartDelay = shortDuration;

            return new ProceduralAnimationSet(scaleAnimation, frontAnimation, backAnimation);
        }
예제 #2
0
        /// <internalonly />
        protected override ProceduralAnimation CreateTransitionAnimation(Panel container, AnimationEffectDirection direction)
        {
            TweenInterpolation interpolation = GetEffectiveInterpolation();

            DoubleAnimation frontAnimation =
                new DoubleAnimation(container.Children[1], UIElement.OpacityProperty, Duration,
                                    (direction == AnimationEffectDirection.Forward ? 0 : 1));
            frontAnimation.Interpolation = interpolation;

            DoubleAnimation backAnimation =
                new DoubleAnimation(container.Children[0], UIElement.OpacityProperty, Duration,
                                    (direction == AnimationEffectDirection.Forward ? 1 : 0));
            backAnimation.Interpolation = interpolation;

            return new ProceduralAnimationSet(frontAnimation, backAnimation);
        }
예제 #3
0
        /// <internalonly />
        protected internal override ProceduralAnimation CreateEffectAnimation(EffectDirection direction)
        {
            FrameworkElement target = GetTarget();

            if (_initialOpacity == -1) {
                _initialOpacity = target.Opacity;
            }

            DoubleAnimation animation;
            if (direction == EffectDirection.Forward) {
                animation = new DoubleAnimation(target, UIElement.OpacityProperty, Duration, _fadeOpacity);
            }
            else {
                animation = new DoubleAnimation(target, UIElement.OpacityProperty, Duration, _initialOpacity);
            }

            animation.AutoReverse = AutoReverse;
            animation.Interpolation = GetEffectiveInterpolation();

            return animation;
        }
예제 #4
0
        /// <internalonly />
        protected internal override ProceduralAnimation CreateEffectAnimation(AnimationEffectDirection direction)
        {
            if (_rotateTransform == null) {
                Transform existingTransform = GetTarget().RenderTransform;
                if (existingTransform != null) {
                    _rotateTransform = existingTransform as RotateTransform;

                    if (_rotateTransform == null) {
                        TransformGroup transformGroup = existingTransform as TransformGroup;

                        if (transformGroup != null) {
                            foreach (Transform transform in transformGroup.Children) {
                                _rotateTransform = transform as RotateTransform;
                                if (_rotateTransform != null) {
                                    break;
                                }
                            }
                        }
                    }
                }

                if (_rotateTransform == null) {
                    throw new InvalidOperationException("The element does not have a rotate transform associated with it.");
                }

                _initialAngle = _rotateTransform.Angle;
            }

            if (_spinAngle != 0) {
                double targetValue = direction == AnimationEffectDirection.Forward ? _initialAngle + _spinAngle : _initialAngle;
                DoubleAnimation animation = new DoubleAnimation(_rotateTransform, RotateTransform.AngleProperty,
                                                                Duration, targetValue);
                animation.Interpolation = GetEffectiveInterpolation();
                animation.AutoReverse = AutoReverse;

                return animation;
            }

            return null;
        }
예제 #5
0
        protected override ProceduralAnimation CreateEffectAnimation(EffectDirection direction)
        {
            FrameworkElement target = GetTarget();

            ScaleTransform scaleTransform = target.RenderTransform as ScaleTransform;
            if (scaleTransform == null) {
                scaleTransform = new ScaleTransform();
                target.RenderTransform = scaleTransform;
                target.RenderTransformOrigin = new Point(0.5, 0.5);
            }

            TimeSpan halfDuration = TimeSpan.FromMilliseconds(Duration.TotalMilliseconds / 2);
            TweenInterpolation interpolation = GetEffectiveInterpolation();

            // A FlashBulb effect basically grows the element and makes it transparent
            // half way and then restores the element to its initial state during the
            // 2nd half of the animation.
            // This is accomplished with three animations that auto-reverse.
            // As a result the animations are the same regardless of effect direction.
            DoubleAnimation opacityAnimation =
                new DoubleAnimation(target, UIElement.OpacityProperty, halfDuration, 0.25);
            DoubleAnimation scaleXAnimation =
                new DoubleAnimation(scaleTransform, ScaleTransform.ScaleXProperty, halfDuration, 1.1);
            DoubleAnimation scaleYAnimation =
                new DoubleAnimation(scaleTransform, ScaleTransform.ScaleYProperty, halfDuration, 1.1);

            opacityAnimation.Interpolation = interpolation;
            scaleXAnimation.Interpolation = interpolation;
            scaleYAnimation.Interpolation = interpolation;

            // Create a composite animation that plays all three in parallel
            ProceduralAnimation animation =
                new ProceduralAnimationSet(opacityAnimation, scaleXAnimation, scaleYAnimation);
            animation.AutoReverse = true;

            return animation;
        }
예제 #6
0
        /// <internalonly />
        protected override ProceduralAnimation CreateTransitionAnimation(Panel container, AnimationEffectDirection direction)
        {
            bool forward = direction == AnimationEffectDirection.Forward;
            double width = container.ActualWidth;
            double height = container.ActualHeight;

            TranslateTransform topTransform = null;
            TranslateTransform bottomTransform = null;
            Transform existingTransform = null;

            FrameworkElement topContent = (FrameworkElement)container.Children[1];
            FrameworkElement bottomContent = (FrameworkElement)container.Children[0];

            existingTransform = topContent.RenderTransform;
            if (existingTransform != null) {
                topTransform = existingTransform as TranslateTransform;

                if (topTransform == null) {
                    TransformGroup transformGroup = existingTransform as TransformGroup;

                    if (transformGroup != null) {
                        foreach (Transform transform in transformGroup.Children) {
                            topTransform = transform as TranslateTransform;
                            if (topTransform != null) {
                                break;
                            }
                        }
                        if (topTransform == null) {
                            topTransform = new TranslateTransform();
                            transformGroup.Children.Add(topTransform);
                        }
                    }
                }
            }
            existingTransform = bottomContent.RenderTransform;
            if (existingTransform != null) {
                bottomTransform = existingTransform as TranslateTransform;

                if (bottomTransform == null) {
                    TransformGroup transformGroup = existingTransform as TransformGroup;

                    if (transformGroup != null) {
                        foreach (Transform transform in transformGroup.Children) {
                            bottomTransform = transform as TranslateTransform;
                            if (bottomTransform != null) {
                                break;
                            }
                        }
                        if (bottomTransform == null) {
                            bottomTransform = new TranslateTransform();
                            transformGroup.Children.Add(bottomTransform);
                        }
                    }
                }
            }

            if (topTransform == null) {
                topTransform = new TranslateTransform();
                topContent.RenderTransform = topTransform;
            }
            if (bottomTransform == null) {
                bottomTransform = new TranslateTransform();
                bottomContent.RenderTransform = bottomTransform;
            }

            SlideAnimation slideAnimation = new SlideAnimation(container, Duration, forward);
            DoubleAnimation topAnimation = null;
            DoubleAnimation bottomAnimation = null;
            switch (_mode) {
                case SlideMode.Left:
                    if (forward) {
                        bottomTransform.X = width;
                        topAnimation = new DoubleAnimation(topTransform, TranslateTransform.XProperty, Duration, -width);
                        bottomAnimation = new DoubleAnimation(bottomTransform, TranslateTransform.XProperty, Duration, 0);
                    }
                    else {
                        topTransform.X = -width;
                        topAnimation = new DoubleAnimation(topTransform, TranslateTransform.XProperty, Duration, 0);
                        bottomAnimation = new DoubleAnimation(bottomTransform, TranslateTransform.XProperty, Duration, width);
                    }
                    break;
                case SlideMode.Right:
                    if (forward) {
                        bottomTransform.X = -width;
                        topAnimation = new DoubleAnimation(topTransform, TranslateTransform.XProperty, Duration, width);
                        bottomAnimation = new DoubleAnimation(bottomTransform, TranslateTransform.XProperty, Duration, 0);
                    }
                    else {
                        topTransform.X = width;
                        topAnimation = new DoubleAnimation(topTransform, TranslateTransform.XProperty, Duration, 0);
                        bottomAnimation = new DoubleAnimation(bottomTransform, TranslateTransform.XProperty, Duration, -width);
                    }
                    break;
                case SlideMode.Up:
                    if (forward) {
                        bottomTransform.Y = height;
                        topAnimation = new DoubleAnimation(topTransform, TranslateTransform.YProperty, Duration, -height);
                        bottomAnimation = new DoubleAnimation(bottomTransform, TranslateTransform.YProperty, Duration, 0);
                    }
                    else {
                        topTransform.Y = -height;
                        topAnimation = new DoubleAnimation(topTransform, TranslateTransform.YProperty, Duration, 0);
                        bottomAnimation = new DoubleAnimation(bottomTransform, TranslateTransform.YProperty, Duration, height);
                    }
                    break;
                case SlideMode.Down:
                    if (forward) {
                        bottomTransform.Y = -height;
                        topAnimation = new DoubleAnimation(topTransform, TranslateTransform.YProperty, Duration, height);
                        bottomAnimation = new DoubleAnimation(bottomTransform, TranslateTransform.YProperty, Duration, 0);
                    }
                    else {
                        topTransform.Y = height;
                        topAnimation = new DoubleAnimation(topTransform, TranslateTransform.YProperty, Duration, 0);
                        bottomAnimation = new DoubleAnimation(bottomTransform, TranslateTransform.YProperty, Duration, -height);
                    }
                    break;
            }

            TweenInterpolation interpolation = GetEffectiveInterpolation();
            topAnimation.Interpolation = interpolation;
            bottomAnimation.Interpolation = interpolation;

            return new ProceduralAnimationSet(slideAnimation, topAnimation, bottomAnimation);
        }
예제 #7
0
        /// <internalonly />
        protected internal override ProceduralAnimation CreateEffectAnimation(EffectDirection direction)
        {
            if (_scaleTransform == null) {
                Transform existingTransform = GetTarget().RenderTransform;
                if (existingTransform != null) {
                    _scaleTransform = existingTransform as ScaleTransform;

                    if (_scaleTransform == null) {
                        TransformGroup transformGroup = existingTransform as TransformGroup;

                        if (transformGroup != null) {
                            foreach (Transform transform in transformGroup.Children) {
                                _scaleTransform = transform as ScaleTransform;
                                if (_scaleTransform != null) {
                                    break;
                                }
                            }
                        }
                    }
                }

                if (_scaleTransform == null) {
                    throw new InvalidOperationException("The element does not have a scale transform associated with it.");
                }

                _initialX = _scaleTransform.ScaleX;
                _initialY = _scaleTransform.ScaleY;
            }

            TweenInterpolation interpolation = GetEffectiveInterpolation();
            DoubleAnimation xAnimation = null;
            DoubleAnimation yAnimation = null;

            if (_scaleXRatio != 1) {
                double targetValue = direction == EffectDirection.Forward ? _initialX * _scaleXRatio : _initialX;

                xAnimation = new DoubleAnimation(_scaleTransform, ScaleTransform.ScaleXProperty, Duration,
                                                 targetValue);
                xAnimation.Interpolation = interpolation;
            }

            if (_scaleYRatio != 1) {
                double targetValue = direction == EffectDirection.Forward ? _initialY * _scaleYRatio : _initialY;

                yAnimation = new DoubleAnimation(_scaleTransform, ScaleTransform.ScaleYProperty, Duration,
                                                 targetValue);
                yAnimation.Interpolation = interpolation;
            }

            if ((xAnimation != null) && (yAnimation != null)) {
                ProceduralAnimationSet animation = new ProceduralAnimationSet(xAnimation, yAnimation);
                animation.AutoReverse = AutoReverse;

                return animation;
            }
            else if (xAnimation != null) {
                xAnimation.AutoReverse = AutoReverse;
                return xAnimation;
            }
            else if (yAnimation != null) {
                yAnimation.AutoReverse = AutoReverse;
                return yAnimation;
            }
            return null;
        }
예제 #8
0
        /// <internalonly />
        protected override ProceduralAnimation CreateTransitionAnimation(Panel container, EffectDirection direction)
        {
            FrameworkElement topElement = (FrameworkElement)container.Children[1];
            FrameworkElement bottomElement = (FrameworkElement)container.Children[0];
            ScaleTransform scaleTransform = null;

            Transform existingTransform = topElement.RenderTransform;
            if (existingTransform != null) {
                scaleTransform = existingTransform as ScaleTransform;

                if (scaleTransform == null) {
                    TransformGroup transformGroup = existingTransform as TransformGroup;

                    if (transformGroup != null) {
                        foreach (Transform transform in transformGroup.Children) {
                            scaleTransform = transform as ScaleTransform;
                            if (transform != null) {
                                break;
                            }
                        }
                        if (scaleTransform == null) {
                            scaleTransform = new ScaleTransform();
                            transformGroup.Children.Add(scaleTransform);
                        }
                    }
                }
            }

            if (scaleTransform == null) {
                scaleTransform = new ScaleTransform();
                topElement.RenderTransform = scaleTransform;
            }

            if (_initialScaleX == 0) {
                _initialScaleX = scaleTransform.ScaleX;
                _initialScaleY = scaleTransform.ScaleY;
            }

            scaleTransform.CenterX = container.ActualWidth / 2;
            scaleTransform.CenterY = container.ActualHeight / 2;

            TweenInterpolation interpolation = GetEffectiveInterpolation();
            DoubleAnimation scaleXAnimation;
            DoubleAnimation scaleYAnimation;
            DoubleAnimation fadeAnimation;

            if (direction == EffectDirection.Forward) {
                fadeAnimation = new DoubleAnimation(topElement, UIElement.OpacityProperty, Duration, 0);
                scaleXAnimation = new DoubleAnimation(scaleTransform, ScaleTransform.ScaleXProperty, Duration, _initialScaleX * _scaleRatio);
                scaleYAnimation = new DoubleAnimation(scaleTransform, ScaleTransform.ScaleYProperty, Duration, _initialScaleY * _scaleRatio);
            }
            else {
                fadeAnimation = new DoubleAnimation(topElement, UIElement.OpacityProperty, Duration, 1);
                scaleXAnimation = new DoubleAnimation(scaleTransform, ScaleTransform.ScaleXProperty, Duration, _initialScaleX);
                scaleYAnimation = new DoubleAnimation(scaleTransform, ScaleTransform.ScaleYProperty, Duration, _initialScaleY);
            }

            scaleXAnimation.Interpolation = interpolation;
            scaleYAnimation.Interpolation = interpolation;
            fadeAnimation.Interpolation = interpolation;

            return new ProceduralAnimationSet(scaleXAnimation, scaleYAnimation, fadeAnimation);
        }
예제 #9
0
        /// <internalonly />
        protected internal override ProceduralAnimation CreateEffectAnimation(AnimationEffectDirection direction)
        {
            FrameworkElement target = GetTarget();

            if (_projection == null) {
                _projection = target.Projection as PlaneProjection;
                if (_projection == null) {
                    _projection = new PlaneProjection();
                    _projection.CenterOfRotationX = 0.5;
                    _projection.CenterOfRotationY = 0.5;
                    _projection.CenterOfRotationZ = 0.5;

                    target.Projection = _projection;
                }
            }

            DoubleAnimation zOffsetAnimation =
                new DoubleAnimation(_projection, PlaneProjection.GlobalOffsetZProperty, Duration,
                                    (direction == AnimationEffectDirection.Forward ? Distance : 0));
            zOffsetAnimation.Interpolation = GetEffectiveInterpolation();

            if (_shadowLength == 0) {
                zOffsetAnimation.AutoReverse = AutoReverse;

                return zOffsetAnimation;
            }

            if (_dropShadow == null) {
                _dropShadow = target.Effect as DropShadowEffect;
                if (_dropShadow == null) {
                    _dropShadow = new DropShadowEffect();
                    _dropShadow.BlurRadius = 0;
                    _dropShadow.ShadowDepth = 0;
                    _dropShadow.Color = Colors.Black;
                    _dropShadow.Opacity = 0.5;

                    target.Effect = _dropShadow;
                }
            }

            DoubleAnimation shadowAnimation =
                new DoubleAnimation(_dropShadow, DropShadowEffect.BlurRadiusProperty, Duration,
                                    (direction == AnimationEffectDirection.Forward ? _shadowLength : 0));
            shadowAnimation.Interpolation = GetEffectiveInterpolation();

            ProceduralAnimationSet animationSet = new ProceduralAnimationSet(zOffsetAnimation, shadowAnimation);
            animationSet.AutoReverse = AutoReverse;

            return animationSet;
        }
예제 #10
0
        /// <internalonly />
        protected internal override ProceduralAnimation CreateEffectAnimation(AnimationEffectDirection direction)
        {
            FrameworkElement target = GetTarget();

            if (_projection == null) {
                _projection = target.Projection as PlaneProjection;
                if (_projection == null) {
                    _projection = new PlaneProjection();
                    _projection.CenterOfRotationX = 0.5;
                    _projection.CenterOfRotationY = 0.5;
                    _projection.CenterOfRotationZ = 0.5;
                    target.Projection = _projection;
                }
            }

            List<ProceduralAnimation> animations = new List<ProceduralAnimation>();

            if (_spinAroundXAxis) {
                DoubleAnimation xAnimation =
                    new DoubleAnimation(_projection, PlaneProjection.RotationXProperty, Duration, 360);
                xAnimation.Interpolation = GetEffectiveInterpolation();
                xAnimation.AutoReverse = true;
                animations.Add(xAnimation);
            }
            if (_spinAroundYAxis) {
                DoubleAnimation yAnimation =
                    new DoubleAnimation(_projection, PlaneProjection.RotationYProperty, Duration, 360);
                yAnimation.Interpolation = GetEffectiveInterpolation();
                yAnimation.AutoReverse = true;
                animations.Add(yAnimation);
            }
            if (_spinAroundZAxis) {
                DoubleAnimation zAnimation =
                    new DoubleAnimation(_projection, PlaneProjection.RotationZProperty, Duration, 360);
                zAnimation.Interpolation = GetEffectiveInterpolation();
                zAnimation.AutoReverse = true;
                animations.Add(zAnimation);
            }

            ProceduralAnimationSet animationSet = new ProceduralAnimationSet(animations.ToArray());
            animationSet.AutoReverse = AutoReverse;

            return animationSet;
        }