{"record":{"id":"29cf4cf4d052a8f8","repo":"dotnet/wpf","slug":"microsoft-windows-controls-sr-elementnotkeytipscope","errorCode":null,"errorMessage":"Microsoft.Windows.Controls.SR.ElementNotKeyTipScope","messagePattern":"Microsoft\\.Windows\\.Controls\\.SR\\.ElementNotKeyTipScope","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipService.cs","lineNumber":964,"sourceCode":"            IInputElement inputElement = exactMatchElement as IInputElement;\n            if (inputElement != null)\n            {\n                inputElement.RaiseEvent(eventArgs);\n                eventArgs.RoutedEvent = KeyTipAccessedEvent;\n                inputElement.RaiseEvent(eventArgs);\n            }\n\n            // KeyTips might have been dismissed by one of the event handlers\n            // hence check again.\n            if (State != KeyTipState.None)\n            {\n                object newFocusedElement = Keyboard.FocusedElement;\n                DependencyObject newScope = eventArgs.TargetKeyTipScope;\n                if (newScope != null &&\n                    !KeyTipService.GetIsKeyTipScope(newScope) &&\n                    newScope != _currentGlobalScope)\n                {\n                    throw new InvalidOperationException(Microsoft.Windows.Controls.SR.ElementNotKeyTipScope);\n                }\n                if (newScope == null &&\n                    KeyTipService.GetIsKeyTipScope(exactMatchElement))\n                {\n                    newScope = exactMatchElement;\n                }\n\n                if (newScope != null)\n                {\n                    // Show keytips for new scope in a dispatcher operation.\n                    Dispatcher.CurrentDispatcher.BeginInvoke(\n                        (Action)delegate()\n                        {\n                            ShowKeyTipsForScope(newScope, true);\n                        },\n                        DispatcherPriority.Loaded);\n                }\n                else","sourceCodeStart":946,"sourceCodeEnd":982,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipService.cs#L946-L982","documentation":"KeyTipService handles focus-scope changes while key tips are active. If the pending focus target (TargetKeyTipScope) is not itself a registered key tip scope (KeyTipService.GetIsKeyTipScope returns false) and is not the current global scope, the service throws InvalidOperationException (SR.ElementNotKeyTipScope) because key tip navigation can only move focus into designated key tip scopes.","triggerScenarios":"During key tip navigation, an element sets Keyboard focus (or TargetKeyTipScope) to a DependencyObject that was never marked as a key tip scope via KeyTipService.SetIsKeyTipScope(element, true), while key tips are active.","commonSituations":"Custom controls stealing focus inside their key-tip-activated command; third-party controls that move focus without registering as key tip scopes; refactors that remove the IsKeyTipScope attached-property setting.","solutions":["Mark the target element as a key tip scope: KeyTipService.SetIsKeyTipScope(targetElement, true)","Ensure focus changes during key tip mode target either a registered key tip scope or the current global scope","Defer the focus change until after key tips are dismissed (e.g. in the Dispatcher at background priority after KeyTipService exits)","Catch InvalidOperationException and fall back to focusing the current global scope"],"exampleFix":"// before\nmyPanel.Focus(); // not a registered key tip scope -> throws during key tip navigation\n// after\nKeyTipService.SetIsKeyTipScope(myPanel, true);\nmyPanel.Focus();","handlingStrategy":"validation","validationCode":"if (KeyTipService.GetIsKeyTipScope(target) || target == /* current global scope */) target.Focus();","typeGuard":"bool IsKeyTipScopeTarget(DependencyObject target) => KeyTipService.GetIsKeyTipScope(target);\n","tryCatchPattern":"try { target.Focus(); }\ncatch (InvalidOperationException) { /* target is not a key tip scope; focus global scope instead */ }","preventionTips":["Register custom focus targets with KeyTipService.SetIsKeyTipScope(element, true)","Only redirect focus to registered key tip scopes while key tips are active","Defer non-scope focus changes until key tip mode exits","Audit custom controls for focus changes triggered by key tip activation"],"tags":["wpf","ribbon","keytips","focus","invalid-state"],"backgroundTag":"invalid-state-transition","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"}