Browse Source

Use the target Animatible as an anchor for the binding.

pull/1768/head
Jeremy Koritzinsky 8 years ago
parent
commit
a52d9c812d
  1. 18
      src/Avalonia.Animation/Animation.cs
  2. 6
      src/Avalonia.Animation/AnimatorKeyFrame.cs

18
src/Avalonia.Animation/Animation.cs

@ -80,7 +80,7 @@ namespace Avalonia.Animation
this.CollectionChanged += delegate { _isChildrenChanged = true; };
}
private void InterpretKeyframes()
private IList<IAnimator> InterpretKeyframes(Animatable control)
{
var handlerList = new List<(Type type, AvaloniaProperty property)>();
var animatorKeyFrames = new List<AnimatorKeyFrame>();
@ -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;
}
/// <summary>
@ -149,15 +147,9 @@ namespace Avalonia.Animation
/// <inheritdocs/>
public IDisposable Apply(Animatable control, IObservable<bool> 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;
}

6
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);
}
}

Loading…
Cancel
Save