{"record":{"id":"d8101b908f205ace","repo":"dotnet/wpf","slug":"sr-changenotallowedaftershow","errorCode":null,"errorMessage":"SR.ChangeNotAllowedAfterShow","messagePattern":"SR\\.ChangeNotAllowedAfterShow","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs","lineNumber":794,"sourceCode":"        /// Whether or not the Window uses per-pixel opacity\n        /// </summary>\n        public bool AllowsTransparency\n        {\n            get { return (bool)GetValue(AllowsTransparencyProperty); }\n            set { SetValue(AllowsTransparencyProperty, BooleanBoxes.Box(value)); }\n        }\n\n        private static void OnAllowsTransparencyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\n        {\n        }\n\n        private static object CoerceAllowsTransparency(DependencyObject d, object value)\n        {\n            value = VerifyAccessCoercion(d, value);\n\n            if (!((Window) d).IsSourceWindowNull)\n            {\n                throw new InvalidOperationException(SR.ChangeNotAllowedAfterShow);\n            }\n\n            return value;\n        }\n\n        /// <summary>\n        ///     The DependencyProperty for TitleProperty.\n        ///     Flags:              None\n        ///     Default Value:      String.Empty\n        /// </summary>\n        public static readonly DependencyProperty TitleProperty =\n                DependencyProperty.Register(\"Title\", typeof(String), typeof(Window),\n                        new FrameworkPropertyMetadata(String.Empty,\n                                new PropertyChangedCallback(_OnTitleChanged)),\n                        new ValidateValueCallback(_ValidateText));\n        /// <summary>\n        ///     The data that will be displayed as the title of the window.\n        ///     Hosts are free to display the title in any manner that they","sourceCodeStart":776,"sourceCodeEnd":812,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs#L776-L812","documentation":"Window.CoerceAllowsTransparency is the dependency-property coercion callback for AllowsTransparency. Once the window's HWND (source window) has been created - i.e. the window has been shown - WPF forbids changing AllowsTransparency and throws InvalidOperationException(SR.ChangeNotAllowedAfterShow). The value affects the native window style at creation time only.","triggerScenarios":"Setting AllowsTransparency (directly or via a style/binding/coercion) after Show(), ShowDialog(), or the window handle has been created; binding AllowsTransparency to a value that changes at runtime.","commonSituations":"Toggling transparency at runtime to switch chrome modes; a data-bound AllowsTransparency that updates after the window loads; setting the property in a Loaded handler instead of the constructor.","solutions":["Set AllowsTransparency in the Window constructor before Show/ShowDialog","If runtime change is needed, close the window, change the value, and create/show a new window instance","Remove bindings/styles that mutate AllowsTransparency after window creation","Check WindowInteropHelper(window).Handle availability / IsSourceWindowNull before assigning"],"exampleFix":"// before\npublic MainWindow() { InitializeComponent(); }\nprivate void ToggleTransparency() {\n    AllowsTransparency = true; // throws after Show()\n}\n// after\npublic MainWindow() {\n    InitializeComponent();\n    AllowsTransparency = WindowStyle == WindowStyle.None;\n    Background = Brushes.Transparent;\n}","handlingStrategy":"validation","validationCode":"if (window.IsLoaded) { throw new InvalidOperationException(\"Set AllowsTransparency before Show()\"); }\nwindow.AllowsTransparency = desired;","typeGuard":"bool CanSetAllowsTransparency(Window w) => !w.IsLoaded;","tryCatchPattern":"try { window.AllowsTransparency = value; } catch (InvalidOperationException ex) when (ex.Message == SR.ChangeNotAllowedAfterShow) { /* recreate window with new value */ }","preventionTips":["Set AllowsTransparency only in the constructor","Avoid bindings/styles that mutate it after Show","Recreate the window for runtime chrome changes"],"tags":["wpf","window","allowstransparency","property-coercion"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}