dotnet/wpf · error · InvalidOperationException
SR.ShowNonActivatedAndMaximized
Error message
SR.ShowNonActivatedAndMaximized
What it means
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.
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.
Example fix
// before
var win = new MainWindow { WindowState = WindowState.Maximized, ShowActivated = false };
win.Show();
// after
var win = new MainWindow { WindowState = WindowState.Normal, ShowActivated = false };
win.Show();
win.Loaded += (s, e) => win.WindowState = WindowState.Maximized; Defensive patterns
Strategy: validation
Validate before calling
if (win.WindowState == WindowState.Maximized && !win.ShowActivated)
throw new InvalidOperationException("Maximized windows must have ShowActivated=true in WPF."); Try / catch
try { win.Show(); }
catch (InvalidOperationException) { win.ShowActivated = true; win.Show(); } Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- (no message - parameterless InvalidOperationException)
- SR.AddText_Invalid
- SR.Animation_NoTextChildren
- SR.Animation_NoTextChildren
- SR.Animation_NoTextChildren
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/915b86cbe6464cc1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs:6943
}
}
private void VerifyConsistencyWithAllowsTransparency(WindowStyle style)
{
if (AllowsTransparency && style != WindowStyle.None)
{
throw new InvalidOperationException(SR.MustUseWindowStyleNone);
}
}
private void VerifyConsistencyWithShowActivated()
{
//
// We don't support to show a maximized non-activated window.
// Don't check this consistency in a RBW (would break because Visibility is set when launching the RBW).
//
if (!_inTrustedSubWindow && WindowState == WindowState.Maximized && !ShowActivated)
throw new InvalidOperationException(SR.ShowNonActivatedAndMaximized);
}
private static bool IsValidSizeToContent(SizeToContent value)
{
return value == SizeToContent.Manual ||
value == SizeToContent.Width ||
value == SizeToContent.Height ||
value == SizeToContent.WidthAndHeight;
}
private static bool IsValidResizeMode(ResizeMode value)
{
return value == ResizeMode.NoResize
|| value == ResizeMode.CanMinimize
|| value == ResizeMode.CanResize
|| value == ResizeMode.CanResizeWithGrip;
}
View on GitHub (pinned to 81131a70a4)