dotnet/wpf · error · ElementNotEnabledException
ElementNotEnabledException
Error message
ElementNotEnabledException
What it means
WindowsListView's IScrollProvider.Scroll throws ElementNotEnabledException when the list-view HWND is disabled. Per the Scroll pattern contract, scrolling a disabled control is not allowed, so the provider checks IsWindowEnabled before delegating to WindowScroll.Scroll.
Solutions
- Check element IsEnabled (or Scroll availability) before invoking Scroll.
- Wait for the control to be re-enabled, then retry the scroll.
- Catch ElementNotEnabledException and fall back to keyboard-based scrolling if applicable.
- Fix the host app so the list view remains enabled when scrolling is expected.
Example fix
// before ((ScrollPattern)lv.GetCurrentPattern(ScrollPattern.Pattern)).Scroll(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount); // after var sp = (ScrollPattern)lv.GetCurrentPattern(ScrollPattern.Pattern); if (lv.Current.IsEnabled) sp.Scroll(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount);
Defensive patterns
Strategy: validation
Validate before calling
if (!element.Current.IsEnabled) { /* wait or skip */ } else { ((ScrollPattern)element.GetCurrentPattern(ScrollPattern.Pattern)).Scroll(h, v); } Try / catch
try { scrollPattern.Scroll(h, v); } catch (ElementNotEnabledException) { /* control disabled */ } Prevention
- Check IsEnabled before scrolling
- Poll for control re-enable after long app operations
- Prefer keyboard scrolling fallback for disabled controls
When it happens
Trigger: Calling the Scroll pattern with any horizontal/vertical ScrollAmount on a list-view element whose window is disabled (WS_DISABLED) at call time.
Common situations: Automating a read-only/disabled list view; the dialog disables the list during long operations; race between app disabling the control and the automation scroll request.
Related errors
- ElementNotEnabledException
- ElementNotEnabledException
- ElementNotEnabledException
- ElementNotEnabledException
- ArgumentOutOfRangeException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1875fc548b05bff1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListView.cs:605
bool ISelectionProvider.IsSelectionRequired
{
get
{
return false;
}
}
#endregion SelectionPattern
#region ScrollPattern
void IScrollProvider.Scroll (ScrollAmount horizontalAmount, ScrollAmount verticalAmount)
{
// Make sure that the control is enabled
if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
{
throw new ElementNotEnabledException();
}
WindowScroll.Scroll (_hwnd, horizontalAmount, verticalAmount, true);
}
void IScrollProvider.SetScrollPercent (double horizontalPercent, double verticalPercent)
{
// Make sure that the control is enabled
if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
{
throw new ElementNotEnabledException();
}
// get the "full size" of the list-view
int size = ApproximateViewRect (_hwnd);
// ApproximateViewRect adds the window edge size, substract it
int cx = NativeMethods.Util.LOWORD (size) /*- 2 * UnsafeNativeMethods.GetSystemMetrics (NativeMethods.SM_CXBORDER)*/;View on GitHub (pinned to 81131a70a4)