dotnet/wpf · warning · InvalidOperationException

SR.DataGridColumnHeaderItemAutomationPeer_Unresizable

Error message

SR.DataGridColumnHeaderItemAutomationPeer_Unresizable

What it means

DataGridColumnHeaderItemAutomationPeer's ITransformProvider.Resize sets Column.Width when resizing is allowed. If OwningDataGrid is null or the column's CanUserResize is false, the resize cannot be performed and the peer throws InvalidOperationException with SR.DataGridColumnHeaderItemAutomationPeer_Unresizable.

Solutions

  1. Set CanUserResize=true on the column (and DataGrid.CanUserResizeColumns=true) before resizing.
  2. Check Column.CanUserResize before invoking Resize and skip if false.
  3. Catch InvalidOperationException and inform the user the column is not resizable.
  4. Set an explicit Width (not star/Auto) if programmatic sizing is needed, since resizing applies a DataGridLength.

Example fix

// before
((ITransformProvider)headerPeer).Resize(200, 22);

// after
if (column.CanUserResize) { ((ITransformProvider)headerPeer).Resize(200, 22); }
Defensive patterns

Strategy: validation

Validate before calling

if (column.CanUserResize) ((ITransformProvider)peer).Resize(width, height);

Type guard

bool IsResizable(DataGridColumn c) => c != null && c.CanUserResize;

Try / catch

try { ((ITransformProvider)peer).Resize(w, h); } catch (InvalidOperationException) { /* column not resizable */ }

Prevention

When it happens

Trigger: Calling ITransformProvider.Resize(width, height) on a column header whose DataGridColumn.CanUserResize is false (or whose DataGrid is unavailable), e.g. columns with Resizable disabled via DataGrid.CanUserResizeColumns=false or per-column settings.

Common situations: UIA tests resizing columns on DataGrids with CanUserResizeColumns="False"; columns whose Width is fixed or sized to Auto/*-star where resizing is disabled; accessibility clients using Transform pattern.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridColumnHeaderItemAutomationPeer.cs:177

            { 
                return false; 
            } 
        }

        void ITransformProvider.Move(double x, double y)
        {
            throw new InvalidOperationException(SR.DataGridColumnHeaderItemAutomationPeer_Unsupported);
        } 

        void ITransformProvider.Resize(double width, double height)
        {
            if (this.OwningDataGrid != null && Column.CanUserResize)
            {
                Column.Width = new DataGridLength(width);
            }
            else
            {
                throw new InvalidOperationException(SR.DataGridColumnHeaderItemAutomationPeer_Unresizable);
            }
        }

        void ITransformProvider.Rotate(double degrees)
        {
            throw new InvalidOperationException(SR.DataGridColumnHeaderItemAutomationPeer_Unsupported);
        }

        #endregion

        #region IVirtualizedItemProvider
        void IVirtualizedItemProvider.Realize()
        {
            if (this.OwningDataGrid != null)
                OwningDataGrid.ScrollIntoView(null,Column);
        }

        #endregion

View on GitHub (pinned to 81131a70a4)