{"record":{"id":"915b86cbe6464cc1","repo":"dotnet/wpf","slug":"sr-shownonactivatedandmaximized","errorCode":null,"errorMessage":"SR.ShowNonActivatedAndMaximized","messagePattern":"SR\\.ShowNonActivatedAndMaximized","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs","lineNumber":6943,"sourceCode":"            }\n        }\n\n        private void VerifyConsistencyWithAllowsTransparency(WindowStyle style)\n        {\n            if (AllowsTransparency && style != WindowStyle.None)\n            {\n                throw new InvalidOperationException(SR.MustUseWindowStyleNone);\n            }\n        }\n\n        private void VerifyConsistencyWithShowActivated()\n        {\n            //\n            // We don't support to show a maximized non-activated window.\n            // Don't check this consistency in a RBW (would break because Visibility is set when launching the RBW).\n            //\n            if (!_inTrustedSubWindow && WindowState == WindowState.Maximized && !ShowActivated)\n                throw new InvalidOperationException(SR.ShowNonActivatedAndMaximized);\n        }\n\n        private static bool IsValidSizeToContent(SizeToContent value)\n        {\n            return value == SizeToContent.Manual ||\n                   value == SizeToContent.Width ||\n                   value == SizeToContent.Height ||\n                   value == SizeToContent.WidthAndHeight;\n        }\n\n        private static bool IsValidResizeMode(ResizeMode value)\n        {\n            return value == ResizeMode.NoResize\n                || value == ResizeMode.CanMinimize\n                || value == ResizeMode.CanResize\n                || value == ResizeMode.CanResizeWithGrip;\n        }\n","sourceCodeStart":6925,"sourceCodeEnd":6961,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs#L6925-L6961","documentation":"Window.Show throws InvalidOperationException when a window is set to WindowState.Maximized with ShowActivated=false and the window is not an internal trusted sub-window. WPF does not support showing a maximized window without activating it, because the Windows platform cannot reliably display a non-activated maximized top-level window. The check is skipped for RBW (restricted browser windows) which set Visibility during launch.","triggerScenarios":"Calling Show() (or ShowDialog reaching the show path) on a Window where WindowState == WindowState.Maximized and ShowActivated == false, and the window was not created internally as a trusted sub-window (_inTrustedSubWindow is false).","commonSituations":"Developers wanting a 'background' maximized window set ShowActivated=\"False\" in XAML together with WindowState=\"Maximized\", or set these properties in code before calling Show; common in kiosk/dashboard apps that try to avoid focus stealing.","solutions":["Remove ShowActivated=\"False\" so the window activates normally when maximized.","Keep ShowActivated=false but set WindowState to Normal; maximize the window after it is shown (e.g. in the Loaded/SourceInitialized handler) via WindowState = WindowState.Maximized.","Maximize via Win32 ShowWindow with SW_SHOWMAXIMIZED/SW_SHOWNOACTIVATE after SourceInitialized if you truly need a no-activate maximized window.","If this is not your window's intent, check that a style/template or base window class is not accidentally setting ShowActivated=false."],"exampleFix":"// before\nvar win = new MainWindow { WindowState = WindowState.Maximized, ShowActivated = false };\nwin.Show();\n// after\nvar win = new MainWindow { WindowState = WindowState.Normal, ShowActivated = false };\nwin.Show();\nwin.Loaded += (s, e) => win.WindowState = WindowState.Maximized;","handlingStrategy":"validation","validationCode":"if (win.WindowState == WindowState.Maximized && !win.ShowActivated)\n    throw new InvalidOperationException(\"Maximized windows must have ShowActivated=true in WPF.\");","typeGuard":null,"tryCatchPattern":"try { win.Show(); }\ncatch (InvalidOperationException) { win.ShowActivated = true; win.Show(); }","preventionTips":["Never combine WindowState=Maximized with ShowActivated=False in XAML or code.","Maximize after showing (in Loaded/SourceInitialized) when avoiding initial focus.","Centralize window creation in a helper that validates these properties before Show."],"tags":["wpf","window","invalid-operation","xaml"],"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"}