{"record":{"id":"3ca82b8216e2df26","repo":"AvaloniaUI/Avalonia","slug":"transitions-collection-cannot-be-reset","errorCode":null,"errorMessage":"Transitions collection cannot be reset.","messagePattern":"Transitions collection cannot be reset\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Animation/Animatable.cs","lineNumber":215,"sourceCode":"            if (!_transitionsEnabled)\n            {\n                return;\n            }\n\n            switch (e.Action)\n            {\n                case NotifyCollectionChangedAction.Add:\n                    AddTransitions(e.NewItems!);\n                    break;\n                case NotifyCollectionChangedAction.Remove:\n                    RemoveTransitions(e.OldItems!);\n                    break;\n                case NotifyCollectionChangedAction.Replace:\n                    RemoveTransitions(e.OldItems!);\n                    AddTransitions(e.NewItems!);\n                    break;\n                case NotifyCollectionChangedAction.Reset:\n                    throw new NotSupportedException(\"Transitions collection cannot be reset.\");\n            }\n        }\n\n        private void AddTransitions(IList items)\n        {\n            if (!_transitionsEnabled)\n            {\n                return;\n            }\n\n            _transitionState ??= new Dictionary<ITransition, TransitionState>();\n\n            for (var i = 0; i < items.Count; ++i)\n            {\n                var t = (ITransition)items[i]!;\n\n                _transitionState.Add(t, new TransitionState\n                {","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Animation/Animatable.cs#L197-L233","documentation":"Thrown by Animatable.OnTransitionsCollectionChanged with NotifyCollectionChangedAction.Reset. The transitions system maintains per-transition state and cannot be rebuilt from a generic reset (Clear()), so Avalonia explicitly disallows resetting the Transitions collection via NotSupportedException.","triggerScenarios":"Calling Animatable.Transitions.Clear() (which raises a Reset action) or reassigning/rebinding a collection that triggers Reset. Any data binding or code that issues CollectionChanged with Action=Reset on the Transitions collection hits this.","commonSituations":"XAML/binding a transitions collection then clearing it; calling .Clear() on Animatable.Transitions in code-behind; a TwoWay/OneWay binding whose source raises NotifyCollectionChangedAction.Reset (e.g. an ObservableCollection re-init); merging/resetting a CompositeCollection.","solutions":["Remove transitions individually (foreach then Remove) instead of Clear(), or replace the collection instance rather than resetting it.","If binding Transitions from a VM, reassign the bound property to a new collection rather than Clear()-ing the existing one.","Avoid Reset notifications from your source collection; use Remove notifications when emptying.","If you need a fresh set, assign a new TransitionCollection and let the setter swap it."],"exampleFix":"// before\nanimatable.Transitions.Clear(); // raises Reset -> throws\n\n// after\nwhile (animatable.Transitions.Count > 0)\n    animatable.Transitions.RemoveAt(0);\n// or:\nanimatable.Transitions = new TransitionCollection();","handlingStrategy":"validation","validationCode":"// never Clear() the transitions collection — remove items or reassign\nif (animatable.Transitions is { Count: > 0 } tc)\n    while (tc.Count > 0) tc.RemoveAt(tc.Count - 1);\nanimatable.Transitions = new TransitionCollection();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call Transitions.Clear(); remove items individually or reassign the collection.","When binding Transitions, replace the VM property with a new collection rather than Clear()-ing.","Ensure source collections raise Remove, not Reset, when emptied.","Audit XAML/code-behind for Clear() on transition collections."],"tags":["animation","transitions","collection","binding","avalonia-base"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}