{"record":{"id":"67601b858e2fc5ac","repo":"dotnet/wpf","slug":"sr-format-sr-unsupportedtriggerintemplate-triggerbase","errorCode":null,"errorMessage":"SR.Format(SR.UnsupportedTriggerInTemplate, triggerBase.GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.UnsupportedTriggerInTemplate, triggerBase\\.GetType\\(\\)\\.Name\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs","lineNumber":982,"sourceCode":"                                    StyleHelper.AddPropertyTriggerWithAction( triggerBase, triggerCondition.Property, ref propertyTriggersWithActions );\n                                }\n                            }\n                            else if( dataTrigger != null )\n                            {\n                                StyleHelper.AddDataTriggerWithAction( triggerBase, dataTrigger.Binding, ref dataTriggersWithActions );\n                            }\n                            else if( multiDataTrigger != null )\n                            {\n                                for( int k = 0; k < multiDataTrigger.Conditions.Count; k++ )\n                                {\n                                    Condition dataCondition = multiDataTrigger.Conditions[k];\n\n                                    StyleHelper.AddDataTriggerWithAction( triggerBase, dataCondition.Binding, ref dataTriggersWithActions );\n                                }\n                            }\n                            else\n                            {\n                                throw new InvalidOperationException(SR.Format(SR.UnsupportedTriggerInTemplate, triggerBase.GetType().Name));\n                            }\n                        }\n                    }\n                    else if( eventTrigger != null )\n                    {\n                        StyleHelper.ProcessEventTrigger(eventTrigger,\n                                                        childIndexFromChildID,\n                                                        ref triggerActions,\n                                                        ref eventDependents,\n                                                        templateRoot,\n                                                        frameworkTemplate,\n                                                        ref eventHandlersStore,\n                                                        ref hasLoadedChangeHandler);\n                    }\n                    else\n                    {\n                        throw new InvalidOperationException(SR.Format(SR.UnsupportedTriggerInTemplate, triggerBase.GetType().Name));\n                    }","sourceCodeStart":964,"sourceCodeEnd":1000,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs#L964-L1000","documentation":"ProcessTemplateTriggers iterates a ControlTemplate's Triggers and throws when the trigger is neither a Trigger, nor a MultiTrigger/DataTrigger usable with actions, i.e. a trigger type unsupported inside templates was supplied (most commonly an EventTrigger in a position the code path treats as a BaseValue trigger, or a custom TriggerBase).","triggerScenarios":"Setting ControlTemplate.Triggers to a trigger type not in {Trigger, MultiTrigger, DataTrigger} — e.g. a hand-added EventTrigger that failed the earlier eventTrigger branch check, or a custom class derived from TriggerBase.","commonSituations":"Copying Style triggers into a template and leaving an EventTrigger in the collection; third-party libraries adding custom trigger types; refactoring a Style into a template without pruning trigger kinds.","solutions":["Remove the unsupported trigger from ControlTemplate.Triggers or replace it with a supported Trigger/MultiTrigger","Move EventTrigger logic out of the template into element.Triggers or style triggers","For custom trigger behavior, implement a TriggerAction-free approach such as visual states or attached behavior","Log triggerBase.GetType() in your validation pass to identify the offending type"],"exampleFix":"// before\n<ControlTemplate.Triggers>\n  <EventTrigger RoutedEvent=\"ButtonBase.Click\"><BeginStoryboard/></EventTrigger>\n</ControlTemplate.Triggers>\n// after\n<ControlTemplate.Triggers>\n  <Trigger Property=\"IsMouseOver\" Value=\"True\">\n    <Setter Property=\"Opacity\" Value=\"0.8\"/>\n  </Trigger>\n</ControlTemplate.Triggers>","handlingStrategy":"validation","validationCode":"foreach (var t in template.Triggers)\n    if (!(t is Trigger || t is MultiTrigger || t is DataTrigger))\n        throw new InvalidOperationException(t.GetType().Name + \" not supported in template triggers\");","typeGuard":"bool TemplateTriggerSupported(TriggerBase t) => t is Trigger || t is MultiTrigger || t is DataTrigger;","tryCatchPattern":"try { fe.Template = template; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"not supported\")) { fe.Triggers.AddRange(template.Triggers); fe.Template = null; }","preventionTips":["Keep EventTriggers in Style.Triggers or element.Triggers, not ControlTemplate.Triggers","Only use the four built-in trigger types in templates","Recheck templates after migrating between .NET versions"],"tags":["wpf","templates","triggers","unsupported"],"backgroundTag":"unsupported-enum-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}