diff --git a/src/Avalonia.Animation/Animation.cs b/src/Avalonia.Animation/Animation.cs index dcfeb7f88f..4e777b36ed 100644 --- a/src/Avalonia.Animation/Animation.cs +++ b/src/Avalonia.Animation/Animation.cs @@ -80,7 +80,7 @@ namespace Avalonia.Animation this.CollectionChanged += delegate { _isChildrenChanged = true; }; } - private void InterpretKeyframes() + private IList InterpretKeyframes(Animatable control) { var handlerList = new List<(Type type, AvaloniaProperty property)>(); var animatorKeyFrames = new List(); @@ -108,7 +108,7 @@ namespace Avalonia.Animation var newKF = new AnimatorKeyFrame(handler, cue); - _subscription.Add(newKF.BindSetter(setter)); + _subscription.Add(newKF.BindSetter(setter, control)); animatorKeyFrames.Add(newKF); } @@ -130,9 +130,7 @@ namespace Avalonia.Animation animator.Add(keyframe); } - foreach(var instance in newAnimatorInstances) - _animators.Add(instance); - + return newAnimatorInstances; } /// @@ -149,15 +147,9 @@ namespace Avalonia.Animation /// public IDisposable Apply(Animatable control, IObservable matchObs) { - if (_isChildrenChanged) - { - InterpretKeyframes(); - _isChildrenChanged = false; - } - - foreach (IAnimator keyframes in _animators) + foreach (IAnimator animator in InterpretKeyframes(control)) { - _subscription.Add(keyframes.Apply(this, control, matchObs)); + _subscription.Add(animator.Apply(this, control, matchObs)); } return this; } diff --git a/src/Avalonia.Animation/AnimatorKeyFrame.cs b/src/Avalonia.Animation/AnimatorKeyFrame.cs index a975f5028f..bd9c7a0184 100644 --- a/src/Avalonia.Animation/AnimatorKeyFrame.cs +++ b/src/Avalonia.Animation/AnimatorKeyFrame.cs @@ -41,18 +41,18 @@ namespace Avalonia.Animation set => SetAndRaise(ValueProperty, ref _value, value); } - public IDisposable BindSetter(IAnimationSetter setter) + public IDisposable BindSetter(IAnimationSetter setter, Animatable targetControl) { Property = setter.Property; var value = setter.Value; if (value is IBinding binding) { - return this.Bind(ValueProperty, binding); + return this.Bind(ValueProperty, binding, targetControl); } else { - return this.Bind(ValueProperty, ObservableEx.SingleValue(value)); + return this.Bind(ValueProperty, ObservableEx.SingleValue(value).ToBinding(), targetControl); } }