dotnet/wpf · error · ElementNotEnabledException
ElementNotEnabledException
Error message
ElementNotEnabledException
What it means
ISelectionItemProvider.Select on SelectorItemAutomationPeer throws ElementNotEnabledException when IsEnabled() reports the underlying selector item is not enabled. UIA providers must refuse selection operations on disabled elements, mirroring how a user cannot click a disabled item. The exception is thrown before any selection logic runs.
Solutions
- Check the item's IsEnabled (or the peer's IsEnabled) before calling Select and skip/abort if false
- Enable the item first (set IsEnabled=true on the item or its container) if selection is legitimately expected
- In UIA test code, re-query the element after enabling since cached state can be stale
Example fix
// before
itemPeer.Select(); // throws if disabled
// after
if (itemPeer.IsEnabled())
{
itemPeer.Select();
} Defensive patterns
Strategy: validation
Validate before calling
if (!((ISelectionItemProvider)peer).IsEnabled())
return; // skip selection of disabled item
((ISelectionItemProvider)peer).Select(); Try / catch
try { peer.Select(); }
catch (ElementNotEnabledException) { /* item disabled; handle or skip */ } Prevention
- Check item IsEnabled before any SelectionItemPattern call
- Keep automation element references fresh (re-query after UI state changes)
- Align test data with business rules that disable certain items
When it happens
Trigger: Calling Select (directly or via a UIA SelectionItemPattern) on an item whose control is disabled — e.g. a ListBoxItem or ComboBoxItem with IsEnabled=false, or an item in a disabled parent Selector.
Common situations: Automation tests driving selection while the item is temporarily disabled (data loading, validation pending); apps that disable items for unavailable options but whose test scripts still try to select them; regressions after a change that started disabling items.
Related errors
- ElementNotEnabledException
- ElementNotEnabledException
- ElementNotEnabledException
- ArgumentOutOfRangeException
- Can only call SelectAll when CanSelectMultipleItems is true.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/dc88a31ff9bb8358.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/SelectorItemAutomationPeer.cs:35
///
public override object GetPattern(PatternInterface patternInterface)
{
if(patternInterface == PatternInterface.SelectionItem)
{
return this;
}
return base.GetPattern(patternInterface);
}
/// <summary>
/// Sets the current element as the selection
/// This clears the selection from other elements in the container
/// </summary>
void ISelectionItemProvider.Select()
{
if(!IsEnabled())
throw new ElementNotEnabledException();
Selector parentSelector = (Selector)(ItemsControlAutomationPeer.Owner);
if (parentSelector == null)
{
throw new InvalidOperationException(SR.UIA_OperationCannotBePerformed);
}
parentSelector.SelectionChange.SelectJustThisItem(parentSelector.NewItemInfo(Item), true /* assumeInItemsCollection */);
}
/// <summary>
/// Adds current element to selection
/// </summary>
void ISelectionItemProvider.AddToSelection()
{
if(!IsEnabled())
throw new ElementNotEnabledException();View on GitHub (pinned to 81131a70a4)