{"record":{"id":"bedd3f886afe25cc","repo":"dotnet/wpf","slug":"sr-format-sr-eventtriggertargetnameunresolvable-eventtrigger","errorCode":null,"errorMessage":"SR.Format(SR.EventTriggerTargetNameUnresolvable, eventTrigger.SourceName)","messagePattern":"SR\\.Format\\(SR\\.EventTriggerTargetNameUnresolvable, eventTrigger\\.SourceName\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs","lineNumber":1087,"sourceCode":"            List<TriggerAction> actionsList = null;\n            bool                actionsListExisted = true;\n            bool                actionsListChanged = false;\n            TriggerAction       action = null;\n\n            FrameworkElementFactory childFef = null;\n\n            // Find a ChildID for the EventTrigger.\n            if( eventTrigger.SourceName == null )\n            {\n                eventTrigger.TriggerChildIndex = 0;\n            }\n            else\n            {\n                int childIndex = StyleHelper.QueryChildIndexFromChildName(eventTrigger.SourceName, childIndexFromChildName);\n\n                if( childIndex == -1 )\n                {\n                    throw new InvalidOperationException(SR.Format(SR.EventTriggerTargetNameUnresolvable, eventTrigger.SourceName));\n                }\n\n                eventTrigger.TriggerChildIndex = childIndex;\n            }\n\n            // We have at least one EventTrigger - will need triggerActions\n            // if it doesn't already exist\n            if (triggerActions == null)\n            {\n                triggerActions = new HybridDictionary();\n            }\n            else\n            {\n                actionsList = triggerActions[eventTrigger.RoutedEvent] as List<TriggerAction>;\n            }\n\n            // Set up TriggerAction list if one doesn't already exist\n            if (actionsList == null)","sourceCodeStart":1069,"sourceCodeEnd":1105,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs#L1069-L1105","documentation":"ProcessEventTrigger cannot resolve an EventTrigger's SourceName to a named child of the template. When QueryChildIndexFromChildName returns -1, the SourceName does not match any x:Name-ed element in the template, so the trigger has no target and InvalidOperationException is thrown.","triggerScenarios":"EventTrigger.SourceName set to a name that does not exist among the template's named children (childIndexFromChildName lookup fails); applying a shared template whose names differ; renaming a template child without updating EventTrigger.SourceName.","commonSituations":"Copy-pasted XAML where the storyboard targets a child name that was renamed or removed; SourceName referencing an element outside the template; MergedDictionaries templates referencing names from other resources.","solutions":["Make SourceName match an x:Name on an element declared inside the same template","Remove SourceName if the trigger should target the templated parent itself","Search the template for the literal SourceName string to spot typos","Regenerate/refresh BAML after renaming elements so compiled triggers stay in sync"],"exampleFix":"// before\n<EventTrigger RoutedEvent=\"MouseEnter\" SourceName=\"griipPanel\">\n  <BeginStoryboard>...</BeginStoryboard>\n</EventTrigger>\n// after (child is actually named 'gripPanel')\n<EventTrigger RoutedEvent=\"MouseEnter\" SourceName=\"gripPanel\">\n  <BeginStoryboard>...</BeginStoryboard>\n</EventTrigger>","handlingStrategy":"validation","validationCode":"bool TemplateContainsName(ControlTemplate tpl, string name)\n{\n    var names = new HashSet<string>();\n    void Walk(object o) { /* walk XamlReader-loaded tree collecting FrameworkElement.Name */ }\n    Walk(XamlReader.Parse(XamlWriter.Save(tpl)));\n    return names.Contains(name);\n}","typeGuard":null,"tryCatchPattern":"try { control.Template = tpl; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"SourceName\") || ex.Message.Contains(\"name\")) { Log(\"EventTrigger SourceName unresolved: \" + ex.Message); }","preventionTips":["After renaming any template child, search the whole template for its old name","Keep EventTrigger.SourceName within the same template file/scope","Prefer targeting the templated parent (no SourceName) when possible"],"tags":["wpf","templates","eventtrigger","nameresolution"],"backgroundTag":"entity-not-found","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"}