{"record":{"id":"c5ee95484ad4a41c","repo":"dotnet/wpf","slug":"sr-format-sr-unsupportedtriggerinstyle-trigger-gettype-name","errorCode":null,"errorMessage":"SR.Format(SR.UnsupportedTriggerInStyle, trigger.GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.UnsupportedTriggerInStyle, trigger\\.GetType\\(\\)\\.Name\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs","lineNumber":786,"sourceCode":"                                StyleHelper.AddPropertyTriggerWithAction(trigger, triggerCondition.Property, ref this.PropertyTriggersWithActions);\n                            }\n                        }\n                        else if (trigger is DataTrigger)\n                        {\n                            StyleHelper.AddDataTriggerWithAction(trigger, ((DataTrigger)trigger).Binding, ref this.DataTriggersWithActions);\n                        }\n                        else if (trigger is MultiDataTrigger multiDataTrigger)\n                        {\n                            for (int k = 0; k < multiDataTrigger.Conditions.Count; k++)\n                            {\n                                Condition dataCondition = multiDataTrigger.Conditions[k];\n\n                                StyleHelper.AddDataTriggerWithAction(trigger, dataCondition.Binding, ref this.DataTriggersWithActions);\n                            }\n                        }\n                        else\n                        {\n                            throw new InvalidOperationException(SR.Format(SR.UnsupportedTriggerInStyle, trigger.GetType().Name));\n                        }\n                    }\n\n                    // Set things up to handle EventTrigger\n                    EventTrigger eventTrigger = trigger as EventTrigger;\n                    if( eventTrigger != null )\n                    {\n                        if( eventTrigger.SourceName != null && eventTrigger.SourceName.Length > 0 )\n                        {\n                            throw new InvalidOperationException(SR.Format(SR.EventTriggerOnStyleNotAllowedToHaveTarget, eventTrigger.SourceName));\n                        }\n\n                        StyleHelper.ProcessEventTrigger(eventTrigger,\n                                                        null /*_childIndexFromChildID*/,\n                                                        ref _triggerActions,\n                                                        ref EventDependents,\n                                                        null /*_templateFactoryRoot*/,\n                                                        null,","sourceCodeStart":768,"sourceCodeEnd":804,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs#L768-L804","documentation":"Style.Triggers only supports Trigger, MultiTrigger, DataTrigger, and MultiDataTrigger (plus EventTrigger handled separately). Any other TriggerBase-derived type (e.g. EventTrigger misuse aside, custom triggers) is rejected by ProcessVisualTriggers with InvalidOperationException naming the trigger's type.","triggerScenarios":"Adding an unsupported TriggerBase subclass to Style.Triggers before Seal — e.g. a custom trigger type, or a template-only trigger type instantiated in code and added to a Style.","commonSituations":"Custom TriggerBase subclasses written by developers expecting style support; library migration where a template-specific trigger is placed in a style; code that generically adds all triggers from a list without filtering by type.","solutions":["Use only Trigger, MultiTrigger, DataTrigger, MultiDataTrigger (and EventTrigger for routed events) in Style.Triggers.","If a custom trigger is required, implement it as a property with a converter used by a DataTrigger binding, or use a template trigger inside a ControlTemplate.","Filter the trigger collection by type before adding to Style.Triggers."],"exampleFix":"// before\nstyle.Triggers.Add(myCustomTrigger); // custom TriggerBase subclass, throws\n// after\nvar dataTrigger = new DataTrigger {\n  Binding = new Binding(\"IsCustomState\"),\n  Value = true\n};\ndataTrigger.Setters.Add(new Setter(Control.BackgroundProperty, Brushes.Red));\nstyle.Triggers.Add(dataTrigger);","handlingStrategy":"type-guard","validationCode":"var allowed = new[] { typeof(Trigger), typeof(MultiTrigger), typeof(DataTrigger), typeof(MultiDataTrigger), typeof(EventTrigger) };\nforeach (var t in triggers)\n    if (!allowed.Contains(t.GetType()))\n        throw new InvalidOperationException($\"{t.GetType().Name} is not supported in Style.Triggers.\");","typeGuard":"static bool IsStyleSupportedTrigger(TriggerBase t) =>\n  t is Trigger or MultiTrigger or DataTrigger or MultiDataTrigger or EventTrigger;","tryCatchPattern":"try { style.Seal(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"trigger\")) { log.Error(\"Unsupported trigger in style\", ex); }","preventionTips":["Restrict Style.Triggers content to Trigger/MultiTrigger/DataTrigger/MultiDataTrigger (+EventTrigger).","Replace custom trigger types with DataTrigger bindings or attached-property behaviors.","Filter generic trigger lists by type before adding to a style."],"tags":["wpf","style","triggers","unsupported-type"],"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"}