{"record":{"id":"3b00dd6b7e767820","repo":"dotnet/wpf","slug":"elementnotenabledexception-windowstitlebar","errorCode":null,"errorMessage":"ElementNotEnabledException","messagePattern":"ElementNotEnabledException","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTitleBar.cs","lineNumber":404,"sourceCode":"                            return SR.LocalizedNameWindowsTitleBarButtonClose;\n\n                        default:\n                            return SR.LocalizedNameWindowsTitleBarButtonUnknown;\n                    }\n                }\n            }\n\n            #endregion\n\n            #region Invoke Pattern\n\n            /// Same effect as a click on one of the title bar button\n            void IInvokeProvider.Invoke ()\n            {\n                // Make sure that the control is enabled\n                if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n                {\n                    throw new ElementNotEnabledException();\n                }\n\n                int command;\n                switch (_item)\n                {\n                    case NativeMethods.INDEX_TITLEBAR_MINBUTTON :\n                        if ((WindowStyle & NativeMethods.WS_MINIMIZE) != 0)\n                            command = NativeMethods.SC_RESTORE;\n                        else\n                            command = NativeMethods.SC_MINIMIZE;\n                        break;\n\n                    case NativeMethods.INDEX_TITLEBAR_HELPBUTTON :\n                        command = NativeMethods.SC_CONTEXTHELP;\n                        break;\n\n                    case NativeMethods.INDEX_TITLEBAR_MAXBUTTON :\n                        if ((WindowStyle & NativeMethods.WS_MAXIMIZE) != 0)","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTitleBar.cs#L386-L422","documentation":"IInvokeProvider.Invoke on a title bar button first checks SafeNativeMethods.IsWindowEnabled(_hwnd) and throws ElementNotEnabledException when the title bar window is disabled. UIA's Invoke pattern mandates this exception for invoking a disabled element, since the corresponding click would do nothing.","triggerScenarios":"Calling InvokePattern.Invoke() on a title bar button (minimize/maximize/close proxy item) while the window is disabled (IsWindowEnabled false).","commonSituations":"Automation clicking title bar buttons while a modal dialog disables the main window; scripted window management during app startup/shutdown.","solutions":["Check the UIA IsEnabled property before invoking","Catch ElementNotEnabledException and wait/retry until the window is enabled","Close or dismiss the modal state disabling the window"],"exampleFix":"// before\nmaxButton.Invoke();\n// after\nif (maxButton.Current.IsEnabled) maxButton.Invoke(); else RetryWhenEnabled(maxButton);","handlingStrategy":"validation","validationCode":"if (!titleBarButton.Current.IsEnabled) throw new SkipInvokeException();","typeGuard":"bool IsEnabled(AutomationElement el) => el.Current.IsEnabled;","tryCatchPattern":"try { titleBarButton.Invoke(); } catch (ElementNotEnabledException) { WaitUntilEnabled(titleBarButton); titleBarButton.Invoke(); }","preventionTips":["Check IsEnabled before Invoke","Avoid title-bar automation while modal dialogs are open","Prefer app-level APIs (SendMessage WM_SYSCOMMAND) when window state is uncertain"],"tags":["uiautomation","wpf","element-not-enabled","invoke-pattern","title-bar"],"backgroundTag":"unsupported-operation","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"}