private void Animator_AnimationEnded(CompositionPropertyAnimator sender, AnimationEndedEventArgs args) { // Unregister from the event. sender.AnimationEnded -= Animator_AnimationEnded; // When an animator completes, remove it from the list of remaining animators and // Dispose() the animator. int index = _animators.IndexOf(sender); Debug.Assert(index >= 0); sender.Dispose(); _animators.RemoveAt(index); // When no remaining animators, notify that the transition is complete. _runningAnimators--; if ((_runningAnimators == 0) && !_finished) { Debug.Assert(_animators.Count == 0); _finished = true; TransitionFinished(this); } }
// Defines the event functionality when an animation complete. private void OnAnimationEnded(CompositionPropertyAnimator sender, AnimationEndedEventArgs eventArgs) { // For sample sake, explicitly looking for only one animation. if (sender == _animator) { ((ContainerVisual)_target.Parent).Children.Remove(_target); Debug.WriteLine("Animation Complete. Remove Visual from Tree"); // Remove the registration for state event change sender.AnimationEnded -= OnAnimationEnded; } }
// Defines a Keyframe animation to animate offset public void AnimateVisual() { var animation = _compositor.CreateVector3KeyFrameAnimation(); animation.InsertKeyFrame(1.0f, new Vector3(175.0f, 250.0f, 0.0f)); animation.Duration = TimeSpan.FromMilliseconds(2000); _animator = _target.ConnectAnimation("Offset", animation); // Register for the state changed event (end) _animator.AnimationEnded += OnAnimationEnded; _animator.Start(); }
private void RotationAngle_AnimationEnded(CompositionPropertyAnimator sender, AnimationEndedEventArgs args) { sender.AnimationEnded -= RotationAngle_AnimationEnded; StartNewRotationAnimation(); }
public void InsertAnimator(CompositionPropertyAnimator animator) { animator.AnimationEnded += Animator_AnimationEnded; _animators.Add(animator); }
private void StartNewRotationAnimation() { // Stop previous animator. if (_rotationAnimator != null) { _rotationAnimator.Dispose(); _rotationAnimator = null; } // Build a custom animation that takes a random amount of time to move to the new // angle value. var angle = ((float)s_random.NextDouble()) * 20.0f - 10.0f; var rotationAnimation = _frame.Compositor.CreateScalarKeyFrameAnimation(); rotationAnimation.InsertKeyFrame(1.0f, angle); var duration = s_random.Next(2000, 5000); rotationAnimation.Duration = TimeSpan.FromMilliseconds(duration); // Start new animator playing. _rotationAnimator = _frame.ConnectAnimation("RotationAngle", rotationAnimation); _rotationAnimator.AnimationEnded += RotationAngle_AnimationEnded; _rotationAnimator.Start(); }
public void Dispose() { if (_rotationAnimator != null) { _rotationAnimator.Dispose(); _rotationAnimator = null; } if (_offsetAnimator != null) { _offsetAnimator.Dispose(); _offsetAnimator = null; } if (_selectedFrame != null) { _selectedFrame.Dispose(); _selectedFrame = null; } if (_content != null) { _content.Dispose(); _content = null; } if (_frame != null) { _frame.Dispose(); _frame = null; } if (_saturationEffect != null) { _saturationEffect.Dispose(); _saturationEffect = null; } // STEP4c: Clean-up effect animations. if (_saturationAnimator != null) { _saturationAnimator.Dispose(); _saturationAnimator = null; } }
public void ApplyDesaturationAnimation(CompositionAnimation animation) { if (_saturationAnimator != null) { _saturationAnimator.Dispose(); _saturationAnimator = null; } if (_saturationEffect != null) { _saturationAnimator = _saturationEffect.Properties.ConnectAnimation( "myEffect.Saturation", animation); _saturationAnimator.Start(); } }
public virtual void Dispose() { if (Property != null) { TargetVisual?.DisconnectAnimation(Property); } CompositionAnimation?.Dispose(); CompositionAnimation = null; Animator?.Dispose(); Animator = null; }