{"record":{"id":"bf56bc32082f6a46","repo":"stride3d/stride","slug":"todo-several-events-found-find-a-way-to-decide-the-most","errorCode":null,"errorMessage":"TODO: several events found, find a way to decide the most relevant one.","messagePattern":"TODO: several events found, find a way to decide the most relevant one\\.","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Behaviors/OnEventBehavior.cs","lineNumber":78,"sourceCode":"        /// </summary>\n        protected abstract void OnEvent();\n\n        /// <inheritdoc/>\n        protected override void OnAttached()\n        {\n            if (EventName == null)\n                throw new ArgumentException($\"The EventName property must be set on behavior '{GetType().FullName}'.\");\n\n            var eventOwnerType = EventOwnerType ?? AssociatedObject.GetType();\n\n            var uiElement = AssociatedObject as UIElement;\n\n            var routedEvents = EventManager.GetRoutedEvents().Where(x => x.Name == EventName && x.OwnerType.IsAssignableFrom(eventOwnerType)).ToArray();\n\n            if (uiElement != null && routedEvents.Length > 0)\n            {\n                if (routedEvents.Length > 1)\n                    throw new NotImplementedException(\"TODO: several events found, find a way to decide the most relevant one.\");\n\n                routedEvent = routedEvents.First();\n                uiElement.AddHandler(routedEvent, routedEventHandler);\n            }\n            else\n            {\n                var eventInfo = AssociatedObject.GetType().GetEvent(EventName);\n\n                if (eventInfo == null)\n                    throw new InvalidOperationException($\"Impossible to find a valid event named '{EventName}'.\");\n\n                eventHandler = AnonymousEventHandler.RegisterEventHandler(eventInfo, AssociatedObject, OnEvent);\n            }\n        }\n\n        /// <inheritdoc/>\n        protected override void OnDetaching()\n        {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Behaviors/OnEventBehavior.cs#L60-L96","documentation":"OnEventBehavior.OnAttached throws NotImplementedException when more than one routed event with the same name matches the event owner type. The library cannot decide which routed event is the most relevant to subscribe to. This is an intentional unfinished-code guard, not an expected runtime condition.","triggerScenarios":"Attaching the behavior to a UIElement when EventManager.GetRoutedEvents() contains multiple RoutedEvents with the same Name whose OwnerType is assignable from the event owner type (e.g. name collision across class hierarchies).","commonSituations":"Custom or third-party controls defining routed events whose names clash with built-in WPF events; using an ambiguous EventName that exists on both a base class and an attached class.","solutions":["Use a more specific EventName that does not collide with other routed events.","Set EventOwnerType explicitly to disambiguate which owning type's event should be used.","Avoid attaching the behavior to the UIElement path; use the CLR-event path instead.","Patch the library to pick the closest owner type in the hierarchy."],"exampleFix":"// before\n<behaviors:OnEventBehavior EventName=\"Changed\" /> <!-- ambiguous routed event -->\n// after\n<behaviors:OnEventBehavior EventName=\"Changed\" EventOwnerType=\"{x:Type local:MyControl}\" />","handlingStrategy":"fallback","validationCode":"var matches = EventManager.GetRoutedEvents()\n    .Where(x => x.Name == eventName && x.OwnerType.IsAssignableFrom(ownerType)).ToArray();\nif (matches.Length > 1)\n    logger.Warn($\"EventName '{eventName}' is ambiguous: {matches.Length} routed events match.\");","typeGuard":"static bool IsUnambiguousRoutedEvent(string eventName, Type ownerType) =>\n    EventManager.GetRoutedEvents().Count(x => x.Name == eventName && x.OwnerType.IsAssignableFrom(ownerType)) == 1;","tryCatchPattern":"try\n{\n    element.Behaviors.Add(behavior);\n}\ncatch (NotImplementedException ex) when (ex.Message.Contains(\"several events\"))\n{\n    logger.Error(ex, $\"Ambiguous routed event '{behavior.EventName}'; set EventOwnerType\");\n}","preventionTips":["Set EventOwnerType explicitly when the event name may be ambiguous.","Choose EventName values unique across base and attached event classes.","Avoid custom routed event names that collide with built-in WPF events."],"tags":["wpf","routed-events","behavior","not-implemented"],"backgroundTag":"method-not-implemented","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}