{"record":{"id":"87bca6b3c36746bc","repo":"dotnet/wpf","slug":"elementnotenabledexception-windowsupdown","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/WindowsUpDown.cs","lineNumber":205,"sourceCode":"                {\n                    return CreateSpinButtonItem (item);\n                }\n            }\n\n            return this;\n        }\n\n        #endregion\n\n        #region RangeValue Pattern\n\n        // Change the position of the Up/Down\n        void IRangeValueProvider.SetValue (double val)\n        {\n            // Make sure that the control is enabled\n            if (!SafeNativeMethods.IsWindowEnabled (_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            if (double.IsNaN(val))\n            {\n                throw new ArgumentException(SR.InvalidParameter);\n            }\n\n            if (val > Max)\n            {\n                throw new ArgumentOutOfRangeException(\"value\", val, SR.RangeValueMax);\n            }\n            else if (val < Min)\n            {\n                throw new ArgumentOutOfRangeException(\"value\", val, SR.RangeValueMin);\n            }\n\n            short newPos = Convert.ToInt16(val);\n            Misc.ProxySendMessage(_hwnd, NativeMethods.UDM_SETPOS, IntPtr.Zero, NativeMethods.Util.MAKELPARAM(newPos, 0));","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs#L187-L223","documentation":"The IRangeValueProvider.SetValue implementation for the Windows Up/Down (spinner) proxy checks SafeNativeMethods.IsWindowEnabled and throws ElementNotEnabledException when the Win32 control is disabled. This mirrors the UIA rule that value-modifying patterns must not operate on disabled elements.","triggerScenarios":"Calling RangeValuePattern.SetValue on a Spinner (WindowsUpDown) element whose HWND is disabled (IsWindowEnabled returns false), e.g. the parent dialog disabled the control or it is grayed out.","commonSituations":"UI tests setting spinner values while the containing dialog is in a disabled/modal state; automating controls that are disabled until some prerequisite action; forms where the spinner is disabled during async work.","solutions":["Enable the control (fix the app state that disabled it) before setting the value","Check RangeValuePattern or the element's IsEnabled property before calling SetValue","Wrap SetValue in try/catch for ElementNotEnabledException and surface a clear 'control disabled' message","Wait/retry until the element reports IsEnabled == true in the UI test"],"exampleFix":"// before\nrangeValuePattern.SetValue(5); // throws if control disabled\n// after\nif (spinnerElement.Current.IsEnabled)\n    rangeValuePattern.SetValue(5);\nelse\n    throw new SkipException(\"Spinner is disabled\");","handlingStrategy":"validation","validationCode":"if (!spinnerElement.Current.IsEnabled) throw new InvalidOperationException(\"Spinner disabled; cannot SetValue\");","typeGuard":"bool CanSetValue(AutomationElement e) => e.Current.IsEnabled && e.TryGetCurrentPattern(RangeValuePattern.Pattern, out _);","tryCatchPattern":"try { rangeValuePattern.SetValue(v); }\ncatch (ElementNotEnabledException) { log(\"Spinner is disabled\"); }","preventionTips":["Check IsEnabled before invoking value-changing patterns","Enable prerequisite app state before automating the spinner","Wait for controls to become enabled rather than calling immediately"],"tags":["uiautomation","wpf","spinner","element-not-enabled"],"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"}