dotnet/wpf · error · InvalidOperationException

SR.ClipToBoundsNotSupported

Error message

SR.ClipToBoundsNotSupported

What it means

Window.CoerceClipToBounds rejects any attempt to set Window.ClipToBounds to true, because clipping a top-level window to its layout bounds is meaningless for an HWND-based window. Setting true throws InvalidOperationException; false (the default) is accepted. This is a documented WPF restriction on Window.

Solutions

  1. Remove ClipToBounds=true from the Window (it is unnecessary — an HWND window is inherently clipped to its bounds)
  2. Apply ClipToBounds on an inner element such as a Grid or Border if clipping of content is intended
  3. Refactor shared styles so the ClipToBounds setter targets inner elements only (e.g. use x:Key or a more specific selector)

Example fix

// before
<Window ClipToBounds="True">...</Window>
// after
<Window><Grid ClipToBounds="True">...</Grid></Window>
Defensive patterns

Strategy: validation

Validate before calling

if (isWindow && ClipToBounds) throw new ArgumentException("Window.ClipToBounds must be false");

Try / catch

try { window.ClipToBounds = true; } catch (InvalidOperationException) { contentRoot.ClipToBounds = true; }

Prevention

When it happens

Trigger: Setting Window.ClipToBounds="True" in XAML, assigning window.ClipToBounds = true in code, or a style/binding/animation that coerces the property to true.

Common situations: Copy-pasting a UserControl's properties onto a Window, applying a shared style with ClipToBounds=true to all FrameworkElements including the Window, trying to clip overflow animations at the window edge.

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/194738f592a172ce. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs:6321

                // setting this value is allowed.
            }
            else
            {
                throw new InvalidOperationException(SR.TransformNotSupported);
            }

            return value;
        }

        private static void _OnRenderTransformChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
        }

        private static object CoerceClipToBounds(DependencyObject d, object value)
        {
            if ((bool)value)
            {
                throw new InvalidOperationException(SR.ClipToBoundsNotSupported);
            }
            return value;
        }

        private static void _OnClipToBoundsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
        }


        /// <summary>
        ///     Get or create the hidden window used for parenting when ShowInTaskbar == false.
        /// </summary>
        private HwndWrapper EnsureHiddenWindow()
        {
            if (_hiddenWindow == null)
            {
                _hiddenWindow = new HwndWrapper(
                    0, // classStyle

View on GitHub (pinned to 81131a70a4)