/// <internalonly /> protected internal override ProceduralAnimation CreateEffectAnimation(EffectDirection direction) { if (_effects.Count == 0) { throw new InvalidOperationException("A CompositeEffect must have more than 1 nested child effect."); } if (_childrenInitialized == false) { foreach (Effect childEffect in _effects) { ((IAttachedObject)childEffect).Attach(AssociatedObject); } _childrenInitialized = true; } List <ProceduralAnimation> animations = new List <ProceduralAnimation>(_effects.Count); foreach (Effect childEffect in _effects) { EffectDirection childDirection = direction; if (childEffect.AutoReverse) { childDirection = EffectDirection.Forward; } ProceduralAnimation childAnimation = childEffect.CreateEffectAnimation(childDirection); if (childAnimation != null) { animations.Add(childAnimation); } } if (animations.Count != 0) { ProceduralAnimation[] animationItems = animations.ToArray(); if (_composition == EffectComposition.Parallel) { ProceduralAnimationSet animation = new ProceduralAnimationSet(animationItems); animation.AutoReverse = AutoReverse; return(animation); } else { ProceduralAnimationSequence animation = new ProceduralAnimationSequence(animationItems); animation.AutoReverse = AutoReverse; return(animation); } } return(null); }
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); }
/// <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); }