dotnet/wpf · error · ElementNotEnabledException

ElementNotEnabled

Error message

ElementNotEnabled

What it means

PageTextBox's IValueProvider.SetValue throws ElementNotEnabledException when a UI Automation client asks to set a value while the control is not enabled. Automation clients must not set values on disabled controls.

Solutions

  1. Check IsEnabled on the target element before calling SetValue via automation
  2. Enable the control programmatically or via UI before automating the value set
  3. Catch ElementNotEnabledException in automation code and retry after the control becomes enabled

Example fix

// before
((IValueProvider)pattern).SetValue("42");
// after
if (pageTextBox.IsEnabled)
    ((IValueProvider)pattern).SetValue("42");
Defensive patterns

Strategy: validation

Validate before calling

if (!pageTextBox.IsEnabled) { /* skip or wait */ } else ((IValueProvider)pattern).SetValue(value);

Type guard

bool CanSetValue(PageTextBox tb) => tb.IsEnabled && !tb.IsReadOnly;

Try / catch

try { ((IValueProvider)pattern).SetValue(v); } catch (ElementNotEnabledException) { /* wait/retry or skip */ }

Prevention

When it happens

Trigger: A UI Automation client (or test using IValueProvider) calls SetValue on a PageTextBox whose IsEnabled is false.

Common situations: Automation scripts hitting a disabled search/page box; window still initializing; control disabled by a validation state.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/d2d23e643bd76ebb. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/PageTextBox.cs:402

            public override object GetPattern(PatternInterface patternInterface)
            {
                if (patternInterface == PatternInterface.Value)
                {
                    return this;
                }
                else
                {
                    return base.GetPattern(patternInterface);
                }
            }

            void IValueProvider.SetValue(string value)
            {
                ArgumentNullException.ThrowIfNull(value);

                if (!IsEnabled())
                {
                    throw new ElementNotEnabledException();
                }

                PageTextBox owner = (PageTextBox)Owner;

                if (owner.IsReadOnly)
                {
                    throw new ElementNotEnabledException();
                }

                if (owner.IsValidInputString(value))
                {
                    owner.Text = value;
                    owner._isEditingText = true;
                    owner.OnPageNumberEdited();
                }
            }
        }
        #endregion

View on GitHub (pinned to 81131a70a4)