stride3d/stride · error · InvalidOperationException
The given window does not contain a ContentPresenter.
Error message
The given window does not contain a ContentPresenter.
What it means
ShowSystemMenu locates the ContentPresenter that is a direct visual child of the given Window to compute the screen position of the system menu. If the window's control template contains no such presenter, it throws InvalidOperationException. This method is inherently dependent on the window template having a ContentPresenter.
Solutions
- Ensure the Window's ControlTemplate contains a ContentPresenter whose visual parent (nearest Control) is the Window itself.
- Use the overload System.Windows.SystemCommands.ShowSystemMenu(window, point) with an explicit position instead of this helper.
- Ensure OnApplyTemplate has run (window fully loaded) before calling.
Example fix
// before ShowSystemMenu(myCustomChromeWindow); // after System.Windows.SystemCommands.ShowSystemMenu(myCustomChromeWindow, myCustomChromeWindow.PointToScreen(new Point(0, 0)));
Defensive patterns
Strategy: validation
Validate before calling
bool canShow = window.FindVisualChildrenOfType<ContentPresenter>()
.Any(x => Equals(x.FindVisualParentOfType<Control>(), window));
if (canShow) ShowSystemMenu(window); Try / catch
try { SystemCommands.ShowSystemMenu(window); }
catch (InvalidOperationException) { System.Windows.SystemCommands.ShowSystemMenu(window, window.PointToScreen(new Point(0, 0))); } Prevention
- Keep a ContentPresenter directly under the Window in any custom window template.
- Call the helper only after the window template is applied (Loaded event).
- Prefer the explicit point overload for re-templated windows.
When it happens
Trigger: Calling SystemCommands.ShowSystemMenu(window) for a window whose ControlTemplate does not include a ContentPresenter directly parented to the window (custom template without one, or presenter nested deeper under other controls).
Common situations: Heavily customized/retemplated Window (custom chrome, third-party window shell) that renames or nests the presenter; using the method with a Window whose template hasn't been applied yet.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- NotSupportedException
- Unable to reach the ItemsPresenter of the associated…
- Unable to reach the VirtualizingTilePanel of the associated…
- A part named 'PART_LogGridView' must be present in the…
- A part named ' ' must be present in the ControlTemplate…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/3cc270377e9b7cac.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Commands/SystemCommands.cs:110
}
private static void Close([NotNull] Window window)
{
System.Windows.SystemCommands.CloseWindow(window);
}
private static bool CanShowSystemMenu([NotNull] Window window)
{
return HasFlag(window, NativeHelper.WS_SYSMENU);
}
private static void ShowSystemMenu([NotNull] Window window)
{
// Note: as we fetch for the content presenter, this command is a bit dependent of the window control template.
// But both our template and the default (Aero) seems to use one so this is probably ok.
var presenter = window.FindVisualChildrenOfType<ContentPresenter>().FirstOrDefault(x => Equals(x.FindVisualParentOfType<Control>(), window));
if (presenter == null)
throw new InvalidOperationException("The given window does not contain a ContentPresenter.");
System.Windows.SystemCommands.ShowSystemMenu(window, presenter.PointToScreen(new Point(0, 0)));
}
private static bool HasFlag([NotNull] Window window, int flag)
{
var hwnd = new WindowInteropHelper(window).Handle;
var hasFlag = (NativeHelper.GetWindowLong(hwnd, NativeHelper.GWL_STYLE) & flag) != 0;
return hasFlag;
}
}
}
View on GitHub (pinned to 96fad776d2)