dotnet/wpf · error · ElementNotEnabledException
ElementNotEnabledException
Error message
ElementNotEnabledException
What it means
WindowsListViewGroup.CheckControlEnabled throws ElementNotEnabledException (no custom message) when SafeNativeMethods.IsWindowEnabled(_hwnd) reports the underlying ListView window is disabled. It is called at the start of ExpandOrCollapse, so Expand()/Collapse() on a disabled control is rejected as required by the UIA ExpandCollapse pattern contract.
Solutions
- Check the element's IsEnabled property (or IsWindowEnabled) before invoking Expand/Collapse and skip or wait.
- Wait for the blocking modal window to close and the control to re-enable, then retry.
- Catch ElementNotEnabledException and record the control as non-interactive instead of failing the run.
Example fix
// before expandPattern.Expand(); // after if (element.Current.IsEnabled) expandPattern.Expand(); else WaitForEnabled(element, timeout);
Defensive patterns
Strategy: validation
Validate before calling
if (!element.Current.IsEnabled) { WaitForEnabled(element, TimeSpan.FromSeconds(5)); } Try / catch
try { expandPattern.Expand(); }
catch (ElementNotEnabledException) { log.Info("ListView disabled; skipping group expand"); } Prevention
- Check IsEnabled before every pattern invocation on list controls.
- Detect and dismiss modal dialogs before automating the blocked window.
When it happens
Trigger: Calling ExpandCollapsePattern.Expand() or Collapse() on a ListView group whose hosting ListView window is disabled (IsWindowEnabled == false), e.g. while a modal dialog blocks the window.
Common situations: Automation run during a modal dialog, a disabled parent form, or the app intentionally disabling the list; test scripts that don't check IsEnabled before interacting.
Related errors
- Element is not enabled.
- ElementNotEnabledException
- ElementNotEnabledException
- ElementNotEnabledException
- ElementNotEnabledException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f09a49f094b226fe.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewGroup.cs:406
}
int IGridProvider.ColumnCount
{
get
{
return GetColumnCount (_hwnd, ID);
}
}
#endregion Grid Pattern
#region ExpandCollapse Pattern
private void CheckControlEnabled()
{
if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
{
throw new ElementNotEnabledException();
}
}
void IExpandCollapseProvider.Expand()
{
ExpandOrCollapse(false);
}
private bool IsCollapsed()
{
return IsCollapsed(_hwnd, _groupID);
}
internal static bool IsCollapsed(IntPtr hwnd, int groupID)
{
bool isCollapsed = false;
NativeMethods.LVGROUP group = new NativeMethods.LVGROUP();
group.Init(Marshal.SizeOf(typeof(NativeMethods.LVGROUP)));View on GitHub (pinned to 81131a70a4)