{"record":{"id":"000cfd677c67ca0a","repo":"AvaloniaUI/Avalonia","slug":"cannot-set-class-binding-property-classes-class","errorCode":null,"errorMessage":"Cannot set Class Binding property '(Classes.{classPropertyName})' in '{instance.Source}' because the style has an activator.","messagePattern":"Cannot set Class Binding property '\\(Classes\\.(.+?)\\)' in '(.+?)' because the style has an activator\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Styling/Setter.cs","lineNumber":79,"sourceCode":"\n        AvaloniaProperty IValueEntry.Property => EnsureProperty();\n\n        public override string ToString() => $\"Setter: {Property} = {Value}\";\n\n        void IValueEntry.Unsubscribe() { }\n\n        [UnconditionalSuppressMessage(\"Trimming\", \"IL2026\", Justification = TrimmingMessages.ImplicitTypeConversionSupressWarningMessage)]\n        internal override ISetterInstance Instance(IStyleInstance instance, StyledElement target)\n        {\n            if (target is not AvaloniaObject ao)\n                throw new InvalidOperationException(\"Don't know how to instance a style on this type.\");\n            if (Property is null)\n                throw new InvalidOperationException(\"Setter.Property must be set.\");\n            if (Property.IsDirect && instance.HasActivator)\n                throw new InvalidOperationException(\n                    $\"Cannot set direct property '{Property}' in '{instance.Source}' because the style has an activator.\");\n            if (Property.IsClassesBindingProperty(out var classPropertyName) && instance.HasActivator)\n                throw new InvalidOperationException(\n                        $\"Cannot set Class Binding property '(Classes.{classPropertyName})' in '{instance.Source}' because the style has an activator.\");\n\n            if (Value is BindingBase binding)\n                return SetBinding((StyleInstance)instance, ao, binding);\n            else if (Value is ITemplate template && !typeof(ITemplate).IsAssignableFrom(Property.PropertyType))\n                return new PropertySetterTemplateInstance(Property, template);\n            else if (!Property.IsValidValue(Value))\n                throw new InvalidCastException($\"Setter value '{Value}' is not a valid value for property '{Property}'.\");\n            else if (Property.IsDirect)\n                return SetDirectValue(target);\n            else\n                return this;\n        }\n\n        bool IValueEntry.HasValue() => true;\n        object? IValueEntry.GetValue() => Value;\n\n        bool IValueEntry.GetDataValidationState(out BindingValueType state, out Exception? error)","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Styling/Setter.cs#L61-L97","documentation":"Thrown by Setter.Instance when the target property is a Classes-binding property (the `Classes.XXX` pseudo-property used to bind a class membership to an expression) and the style instance has an activator. Binding a class from within a conditional style would create a circular/ambiguous activation, so Avalonia forbids it. The message includes the class property name and the style source.","triggerScenarios":"A Setter targeting `Classes.SomeClass` (a Classes binding property) inside a Style whose selector yields an activator (conditional match). IsClassesBindingProperty returns true and instance.HasActivator is true.","commonSituations":"Trying to drive one pseudo-class/class from another class within a conditional style; binding Classes in a Style rather than in a ControlTheme or activator-less context.","solutions":["Move the Classes-binding Setter into a ControlTheme or an activator-less style.","Drive the class through code-behind or a different binding strategy instead of a conditional style setter.","Re-evaluate whether the class should be bound at all; prefer setting it directly."],"exampleFix":"// before (conditional style binding a class)\nnew Style(s => s.OfType<Control>().Class(\"a\"))\n{\n    Setters = { new Setter(Classes.bProperty, someBinding) }\n}\n\n// after (activator-less ControlTheme setter)\ntheme.Setters.Add(new Setter(Classes.bProperty, someBinding));","handlingStrategy":"validation","validationCode":"foreach (var setter in style.Setters.OfType<Setter>())\n    if (setter.Property?.IsClassesBindingProperty(out _) == true && styleHasActivator)\n        throw new InvalidOperationException(\"Classes-binding properties cannot be set in a conditional style.\");","typeGuard":"static bool IsClassesBinding(AvaloniaProperty? p) => p?.IsClassesBindingProperty(out _) == true;","tryCatchPattern":null,"preventionTips":["Do not bind Classes.XXX from conditional styles.","Move Classes-binding setters into ControlThemes.","Drive class membership via code-behind or view-model state instead."],"tags":["avalonia","styling","setter","classes-binding","activator"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}