dotnet/wpf · error · ElementNotEnabledException

ElementNotEnabledException

Error message

ElementNotEnabledException

What it means

ScrollViewerAutomationPeer's IScrollProvider.Scroll throws ElementNotEnabledException when the ScrollViewer is disabled. The Scroll pattern (like all UIA patterns) refuses to operate on a disabled element.

Solutions

  1. Enable the ScrollViewer (and its ancestors) before scrolling
  2. Verify IsEnabled before calling Scroll
  3. Catch ElementNotEnabledException and wait/retry until the control is enabled

Example fix

// before
scrollPattern.Scroll(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount);
// after
if (scrollViewer.IsEnabled)
    scrollPattern.Scroll(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount);
Defensive patterns

Strategy: validation

Validate before calling

if (!scrollViewer.IsEnabled) { /* wait or enable */ }

Type guard

static bool CanScroll(ScrollViewer sv) => sv?.IsEnabled == true;

Try / catch

try { scrollProvider.Scroll(h, v); }
catch (ElementNotEnabledException) { /* retry after enabled */ }

Prevention

When it happens

Trigger: Calling Scroll(horizontalAmount, verticalAmount) on the Scroll pattern when the ScrollViewer owner has IsEnabled=false.

Common situations: UIA scripts scrolling a viewer inside a disabled container/panel; test automation running while the window is disabled (e.g. modal busy state).

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ScrollViewerAutomationPeer.cs:76

        }


        //-------------------------------------------------------------------
        //
        //  IScrollProvider
        //
        //-------------------------------------------------------------------

        /// <summary>
        /// Request to scroll horizontally and vertically by the specified amount.
        /// The ability to call this method and simultaneously scroll horizontally
        /// and vertically provides simple panning support.
        /// </summary>
        /// <see cref="IScrollProvider.Scroll"/>
        void IScrollProvider.Scroll(ScrollAmount horizontalAmount, ScrollAmount verticalAmount)
        {
            if(!IsEnabled())
                throw new ElementNotEnabledException();

            bool scrollHorizontally = (horizontalAmount != ScrollAmount.NoAmount);
            bool scrollVertically = (verticalAmount != ScrollAmount.NoAmount);

            ScrollViewer owner = (ScrollViewer)Owner;

            if (scrollHorizontally && !HorizontallyScrollable || scrollVertically && !VerticallyScrollable)
            {
                throw new InvalidOperationException(SR.UIA_OperationCannotBePerformed);
            }

            switch (horizontalAmount)
            {
                case ScrollAmount.LargeDecrement:
                    owner.PageLeft();
                    break;
                case ScrollAmount.SmallDecrement:
                    owner.LineLeft();

View on GitHub (pinned to 81131a70a4)