diff --git a/src/Avalonia.Animation/Animation.cs b/src/Avalonia.Animation/Animation.cs index 46b638dcf4..da4b3af38d 100644 --- a/src/Avalonia.Animation/Animation.cs +++ b/src/Avalonia.Animation/Animation.cs @@ -167,12 +167,18 @@ namespace Avalonia.Animation var tcs = new TaskCompletionSource(); if (this.RepeatCount == RepeatCount.Loop) + { tcs.SetException(new InvalidOperationException("Looping animations must not use the Run method.")); + return tcs.Task; + } - this.Done += delegate + this.Done += (sender, args) => { - tcs.SetResult(null); - } + if (sender == control) + tcs.SetResult(null); + else + tcs.SetCanceled(); + }; this.Apply(control, Observable.Return(true));