dotnet/wpf · error · InvalidOperationException
SR.Format(SR.EventTriggerTargetNameUnresolvable…
Error message
SR.Format(SR.EventTriggerTargetNameUnresolvable, eventTrigger.SourceName)
What it means
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.
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
Example fix
// before <EventTrigger RoutedEvent="MouseEnter" SourceName="griipPanel"> <BeginStoryboard>...</BeginStoryboard> </EventTrigger> // after (child is actually named 'gripPanel') <EventTrigger RoutedEvent="MouseEnter" SourceName="gripPanel"> <BeginStoryboard>...</BeginStoryboard> </EventTrigger>
Defensive patterns
Strategy: validation
Validate before calling
bool TemplateContainsName(ControlTemplate tpl, string name)
{
var names = new HashSet<string>();
void Walk(object o) { /* walk XamlReader-loaded tree collecting FrameworkElement.Name */ }
Walk(XamlReader.Parse(XamlWriter.Save(tpl)));
return names.Contains(name);
} Try / catch
try { control.Template = tpl; } catch (InvalidOperationException ex) when (ex.Message.Contains("SourceName") || ex.Message.Contains("name")) { Log("EventTrigger SourceName unresolved: " + ex.Message); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- SR.ChildTemplateInstanceDoesNotExist
- SR.ElementMustBelongToTemplate
- SR.EventTriggerDoesNotEnterExit
- SR.EventTriggerDoNotSetProperties
- SR.Format(SR.CannotChangeAfterSealed, "EventTrigger")
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/bedd3f886afe25cc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs:1087
List<TriggerAction> actionsList = null;
bool actionsListExisted = true;
bool actionsListChanged = false;
TriggerAction action = null;
FrameworkElementFactory childFef = null;
// Find a ChildID for the EventTrigger.
if( eventTrigger.SourceName == null )
{
eventTrigger.TriggerChildIndex = 0;
}
else
{
int childIndex = StyleHelper.QueryChildIndexFromChildName(eventTrigger.SourceName, childIndexFromChildName);
if( childIndex == -1 )
{
throw new InvalidOperationException(SR.Format(SR.EventTriggerTargetNameUnresolvable, eventTrigger.SourceName));
}
eventTrigger.TriggerChildIndex = childIndex;
}
// We have at least one EventTrigger - will need triggerActions
// if it doesn't already exist
if (triggerActions == null)
{
triggerActions = new HybridDictionary();
}
else
{
actionsList = triggerActions[eventTrigger.RoutedEvent] as List<TriggerAction>;
}
// Set up TriggerAction list if one doesn't already exist
if (actionsList == null)View on GitHub (pinned to 81131a70a4)