Exemplo n.º 1
0
        /// <summary>
        /// Creates a new layout animation when an arrange pass starts.
        /// </summary>
        protected void BeginArrange()
        {
            if (_layoutAnimation != null)
            {
                if (_layoutAnimation.IsPlaying)
                {
                    _layoutAnimation.Stop(ProceduralAnimationStopState.Abort);
                }
                _layoutAnimation = null;
            }

            _useAnimation = UseAnimatedLayout;
            _animations   = new List <ProceduralAnimation>();

            if (_useAnimation)
            {
                if (_useDefaultInterpolation)
                {
                    _interpolation = EasingInterpolation.Default;
                }
                else
                {
                    _interpolation = Interpolation;
                    if (_interpolation.IsLinearInterpolation)
                    {
                        _interpolation = null;
                    }
                }
                _duration = Duration;
            }
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        /// <internalonly />
        protected override ProceduralAnimation CreateTransitionAnimation(Panel container, EffectDirection direction)
        {
            TweenInterpolation interpolation = GetEffectiveInterpolation();

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

            frontAnimation.Interpolation = interpolation;

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

            backAnimation.Interpolation = interpolation;

            return(new ProceduralAnimationSet(frontAnimation, backAnimation));
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <internalonly />
        protected internal override ProceduralAnimation CreateEffectAnimation(EffectDirection direction)
        {
            if (_translateTransform == null)
            {
                Transform existingTransform = GetTarget().RenderTransform;
                if (existingTransform != null)
                {
                    _translateTransform = existingTransform as TranslateTransform;

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

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

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

                _initialX = _translateTransform.X;
                _initialY = _translateTransform.Y;
            }

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

            if (_horizontalMovement != 0)
            {
                double targetValue = direction == EffectDirection.Forward ? _horizontalMovement : _initialX;
                xAnimation = new DoubleAnimation(_translateTransform, TranslateTransform.XProperty, Duration, targetValue);
                xAnimation.Interpolation = interpolation;
            }

            if (_verticalMovement != 0)
            {
                double targetValue = direction == EffectDirection.Forward ? _verticalMovement : _initialY;
                yAnimation = new DoubleAnimation(_translateTransform, TranslateTransform.YProperty, 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);
        }
Exemplo n.º 6
0
        /// <internalonly />
        protected override ProceduralAnimation CreateTransitionAnimation(Panel container, EffectDirection direction)
        {
            bool   forward = direction == EffectDirection.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));
        }
Exemplo n.º 7
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));
        }