{"record":{"id":"d2d23e643bd76ebb","repo":"dotnet/wpf","slug":"elementnotenabled","errorCode":null,"errorMessage":"ElementNotEnabled","messagePattern":"ElementNotEnabled","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/PageTextBox.cs","lineNumber":402,"sourceCode":"            public override object GetPattern(PatternInterface patternInterface)\n            {\n                if (patternInterface == PatternInterface.Value)\n                {\n                    return this;\n                }\n                else\n                {\n                    return base.GetPattern(patternInterface);\n                }\n            }\n\n            void IValueProvider.SetValue(string value)\n            {\n                ArgumentNullException.ThrowIfNull(value);\n\n                if (!IsEnabled())\n                {\n                    throw new ElementNotEnabledException();\n                }\n\n                PageTextBox owner = (PageTextBox)Owner;\n\n                if (owner.IsReadOnly)\n                {\n                    throw new ElementNotEnabledException();\n                }\n\n                if (owner.IsValidInputString(value))\n                {\n                    owner.Text = value;\n                    owner._isEditingText = true;\n                    owner.OnPageNumberEdited();\n                }\n            }\n        }\n        #endregion","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/PageTextBox.cs#L384-L420","documentation":"PageTextBox's IValueProvider.SetValue throws ElementNotEnabledException when a UI Automation client asks to set a value while the control is not enabled. Automation clients must not set values on disabled controls.","triggerScenarios":"A UI Automation client (or test using IValueProvider) calls SetValue on a PageTextBox whose IsEnabled is false.","commonSituations":"Automation scripts hitting a disabled search/page box; window still initializing; control disabled by a validation state.","solutions":["Check IsEnabled on the target element before calling SetValue via automation","Enable the control programmatically or via UI before automating the value set","Catch ElementNotEnabledException in automation code and retry after the control becomes enabled"],"exampleFix":"// before\n((IValueProvider)pattern).SetValue(\"42\");\n// after\nif (pageTextBox.IsEnabled)\n    ((IValueProvider)pattern).SetValue(\"42\");","handlingStrategy":"validation","validationCode":"if (!pageTextBox.IsEnabled) { /* skip or wait */ } else ((IValueProvider)pattern).SetValue(value);","typeGuard":"bool CanSetValue(PageTextBox tb) => tb.IsEnabled && !tb.IsReadOnly;","tryCatchPattern":"try { ((IValueProvider)pattern).SetValue(v); } catch (ElementNotEnabledException) { /* wait/retry or skip */ }","preventionTips":["Check IsEnabled before automating value sets","Wait for UI readiness (enabled state) in automation waits","Avoid automating controls disabled by app state"],"tags":["wpf","ui-automation","disabled-control"],"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"}