{"record":{"id":"cdd1f3c954287b31","repo":"dotnet/wpf","slug":"elementnotenabledexception-windowscalendar","errorCode":null,"errorMessage":"ElementNotEnabledException","messagePattern":"ElementNotEnabledException","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsCalendar.cs","lineNumber":354,"sourceCode":"            if (!fUnknown)\n            {\n                return CreateCalendarBits (type, index);\n            }\n\n            return base.ElementProviderFromPoint (x, y);\n        }\n\n        #endregion\n\n        #region Scroll Pattern\n\n        // Request to scroll Horizontally and vertically by the specified amount\n        void IScrollProvider.SetScrollPercent (double horizontalPercent, double verticalPercent)\n        {\n            // Make sure that the control is enabled\n            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            if ((int)verticalPercent != (int)ScrollPattern.NoScroll)\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n            else if ((int)horizontalPercent == (int)ScrollPattern.NoScroll)\n            {\n                return;\n            }\n            else if (horizontalPercent < 0 || horizontalPercent > 100)\n            {\n                throw new ArgumentOutOfRangeException(\"horizontalPercent\", SR.ScrollBarOutOfRange);\n            }\n\n            int cDisplayedMonths = GetMonthCount();\n            DateTime [] dateRange =\n                CreateDateTimeFromSystemTime (GetRawValue (_hwnd, CalendarData.Range));","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsCalendar.cs#L336-L372","documentation":"IScrollProvider.SetScrollPercent on the unsupported WindowsCalendar (month calendar) proxy first verifies the Win32 control is enabled via IsWindowEnabled. If the calendar HWND is disabled, it throws ElementNotEnabledException instead of attempting the scroll.","triggerScenarios":"Calling IScrollProvider.SetScrollPercent (any values) on a calendar element whose HWND is disabled (IsWindowEnabled returns false).","commonSituations":"Automating a calendar hosted on a disabled dialog or inside a disabled parent; attempting scroll while the UI thread has the control disabled during a modal operation.","solutions":["Enable the calendar control (or its parent window) before invoking SetScrollPercent.","Check IWindowProvider.IsEnabled / element enabled state before calling.","Catch ElementNotEnabledException and retry once the control is re-enabled."],"exampleFix":"// before\nscrollPattern.SetScrollPercent(50, ScrollPattern.NoScroll);\n// after\nif (element.CurrentIsEnabled)\n    scrollPattern.SetScrollPercent(50, ScrollPattern.NoScroll);","handlingStrategy":"validation","validationCode":"if (!calendarElement.CurrentIsEnabled)\n    throw new SkipException(\"calendar is disabled; enable before SetScrollPercent\");","typeGuard":"bool CanScroll(AutomationElement el) => el != null && el.CurrentIsEnabled && (bool)el.GetCurrentPropertyValue(ScrollPattern.IsScrollPatternAvailableProperty);","tryCatchPattern":"try { scrollPattern.SetScrollPercent(h, ScrollPattern.NoScroll); }\ncatch (ElementNotEnabledException) { EnableControlThenRetry(); }","preventionTips":["Check element IsEnabled before every pattern call","Ensure parent windows/dialogs are enabled during automation","Wait for UI readiness (enabled state) with polling or events"],"tags":["uiautomation","disabled-control","scroll-pattern"],"backgroundTag":"feature-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"}