diff --git a/src/Avalonia.Base/Rendering/Composition/CompositionObject.cs b/src/Avalonia.Base/Rendering/Composition/CompositionObject.cs index 9392c6a617..708cb49128 100644 --- a/src/Avalonia.Base/Rendering/Composition/CompositionObject.cs +++ b/src/Avalonia.Base/Rendering/Composition/CompositionObject.cs @@ -65,6 +65,18 @@ namespace Avalonia.Rendering.Composition throw new ArgumentException("Unknown property " + propertyName); } + /// Disconnects an animation from the specified property and stops the animation. + /// The name of the property to disconnect the animation from. + public void StopAnimation(string propertyName) + { + if (propertyName is null) + throw new ArgumentNullException(nameof(propertyName)); + if (Server is not ServerObject srv) + return; + var prop = srv.GetCompositionProperty(propertyName) ?? throw new ArgumentException("Unknown property " + propertyName); + srv.Animations?.RemoveAnimationForProperty(prop); + } + /// /// Starts an animation group. /// The StartAnimationGroup method on CompositionObject lets you start CompositionAnimationGroup. @@ -126,6 +138,27 @@ namespace Avalonia.Rendering.Composition throw new ArgumentException(); } + /// Stops an animation group. + /// The animation group to stop. + public void StopAnimationGroup(ICompositionAnimationBase grp) + { + if (grp is CompositionAnimation animation) + { + if (animation.Target == null) + throw new ArgumentException("Animation Target can't be null"); + StopAnimation(animation.Target); + } + else if (grp is CompositionAnimationGroup group) + { + foreach (var a in group.Animations) + { + if (a.Target == null) + throw new ArgumentException("Animation Target can't be null"); + StopAnimation(a.Target); + } + } + } + protected void RegisterForSerialization() { if (Server == null)