{"record":{"id":"4cf99b4f31823d1a","repo":"dotnet/wpf","slug":"sr-format-sr-triggerbase","errorCode":null,"errorMessage":"SR.Format(SR.VisualTriggerSettersIncludeUnsupportedSetterType, setters[i].GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.VisualTriggerSettersIncludeUnsupportedSetterType, setters\\[i\\]\\.GetType\\(\\)\\.Name\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs","lineNumber":300,"sourceCode":"                        }\n                        else\n                        {\n                            target = ProcessParametersVisualTreeChild(dp, target); // name string will get interned\n                        }\n\n                        DynamicResourceExtension dynamicResource = value as DynamicResourceExtension;\n                        if (dynamicResource == null)\n                        {\n                            AddToPropertyValues(target, dp, value, PropertyValueType.Trigger);\n                        }\n                        else\n                        {\n                            AddToPropertyValues(target, dp, dynamicResource.ResourceKey, PropertyValueType.PropertyTriggerResource);\n                        }\n                    }\n                    else\n                    {\n                        throw new InvalidOperationException(SR.Format(SR.VisualTriggerSettersIncludeUnsupportedSetterType, setters[i].GetType().Name));\n                    }\n                }\n            }\n        }\n\n        // Define the DO's inheritance context\n\n        internal override DependencyObject InheritanceContext\n        {\n            get { return _inheritanceContext; }\n        }\n\n        // Receive a new inheritance context (this will be a FE/FCE)\n        internal override void AddInheritanceContext(DependencyObject context, DependencyProperty property)\n        {\n            InheritanceContextHelper.AddInheritanceContext(context,\n                                                              this,\n                                                              ref _hasMultipleInheritanceContexts,","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs#L282-L318","documentation":"TriggerBase.ProcessSettersCollection throws InvalidOperationException (VisualTriggerSettersIncludeUnsupportedSetterType, type name) when a visual trigger's Setters collection contains a Setter-derived type other than Setter or DynamicResource-bearing setters it supports (e.g., EventSetter). Visual/property triggers only accept property setters.","triggerScenarios":"Adding an EventSetter (or other unsupported SetterBase subclass) to a Trigger's Setters collection, in XAML (<EventSetter> inside <Trigger.Setters>) or code.","commonSituations":"Copy-pasting an <EventSetter> from a Style.Setters block into a Trigger.Setters block; programmatically reusing a setters list across style and trigger scopes.","solutions":["Remove EventSetter/unsupported items from the trigger's Setters collection","Handle events in the control or template code instead of trigger setters","Only place plain <Setter> (or supported Setter/DynamicResource) entries in Trigger.Setters"],"exampleFix":"// before\n<Trigger Property=\"IsMouseOver\" Value=\"True\">\n  <Setter Property=\"Background\" Value=\"Red\"/>\n  <EventSetter Event=\"Click\" Handler=\"OnClick\"/>\n</Trigger>\n// after\n<Trigger Property=\"IsMouseOver\" Value=\"True\">\n  <Setter Property=\"Background\" Value=\"Red\"/>\n</Trigger>\n<!-- attach event handler on the element or via EventTrigger/Command -->","handlingStrategy":"type-guard","validationCode":"if (setter is not Setter) throw new InvalidOperationException($\"{setter.GetType().Name} not supported in trigger setters.\");","typeGuard":"static bool IsSupportedTriggerSetter(SetterBase s) => s is Setter;","tryCatchPattern":"try { trigger.Setters.Add(setter); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Setter\")) { /* remove unsupported setter */ }","preventionTips":["Only use plain <Setter> inside Trigger.Setters","Attach event handlers outside trigger setter collections","Don't share SetterBase collections between styles and triggers"],"tags":["wpf","xaml","unsupported-type","setters"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}