{"record":{"id":"5b3b5b87db232a7a","repo":"dotnet/wpf","slug":"elementnotenabledexception-windowstreeview","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/WindowsTreeView.cs","lineNumber":959,"sourceCode":"                    return new int [4] { ProxySimple.Win32ProviderRuntimeIdBase, unchecked((int)(long)_hwnd), highPart, lowPart };\n                }\n                else\n                {\n                    return new int[3] { ProxySimple.Win32ProviderRuntimeIdBase, (int)_hwnd, (int)_hItem };\n                }\n            }\n\n            #endregion\n\n            #region SelectionItem Pattern\n\n            // Selects this element\n            void ISelectionItemProvider.Select ()\n            {\n                // Make sure that the control is enabled\n                if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n                {\n                    throw new ElementNotEnabledException();\n                }\n\n                CheckForElementAvailable();\n\n                // simple case: item already selected\n                if (IsItemSelected())\n                {\n                    return;\n                }\n\n                if (HasMSAAImageMap())\n                {\n                    Invoke();\n                }\n                else\n                {\n                    // try to select an item, hence unselecting everything else\n                    if (!WindowsTreeView.SelectItem(_hwnd, _hItem))","sourceCodeStart":941,"sourceCodeEnd":977,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsTreeView.cs#L941-L977","documentation":"The ISelectionItemProvider.Select implementation on the TreeViewItem proxy first verifies the host tree-view window is enabled via IsWindowEnabled. If the window is disabled, selection cannot proceed and an ElementNotEnabledException is thrown, per UIA contract for disabled elements.","triggerScenarios":"Calling SelectionItemPattern.Select() on a tree-view item while the hosting TreeView window is disabled (IsWindowEnabled == false) — e.g. during a modal operation, ShowDialog, or the app explicitly calling EnableWindow(false).","commonSituations":"Automation running while a modal dialog or busy overlay has disabled the main window; tests interacting with controls whose parent window is disabled to block input.","solutions":["Wait until the host window is enabled (modal dialog closed, EnableWindow(true) called) before selecting.","Check element.Current.IsEnabled == true before invoking selection patterns.","If your code disabled the window, re-enable it prior to automation.","Catch ElementNotEnabledException and retry after the app re-enables the control."],"exampleFix":"// before\nitem.Select();\n// after\nif (!item.Current.IsEnabled)\n    WaitFor(() => item.Current.IsEnabled, timeout);\nitem.Select();","handlingStrategy":"validation","validationCode":"if (!item.Current.IsEnabled) throw new SkipException(\"host window disabled\");","typeGuard":"bool CanInteract(AutomationElement e) => e.Current.IsEnabled;","tryCatchPattern":"try { item.Select(); }\ncatch (ElementNotEnabledException) { WaitForWindowEnabled(); item.Select(); }","preventionTips":["Wait for modal dialogs to close before automating the tree","Poll element.Current.IsEnabled before pattern calls","Avoid EnableWindow(false) during automated runs"],"tags":["uiautomation","winforms","treeview","disabled-element"],"backgroundTag":"element-not-enabled","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"}