MahApps/MahApps.Metro · error · InvalidOperationException
The Light Flyout theme only works if the window theme abides
Error message
The Light Flyout theme only works if the window theme abides the naming convention. See ThemeManager.GetInverseAppTheme for more infos
What it means
Thrown by Flyout.ChangeFlyoutTheme when Theme==FlyoutTheme.Light and the needed light theme cannot be resolved. If the window theme's BaseColorScheme is already Light, the window theme is used directly; otherwise GetInverseTheme is called and returns null when the window theme name doesn't follow the Light/Dark naming convention.
Source
Thrown at src/MahApps.Metro/Controls/Flyout.cs:714
ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, inverseTheme);
break;
case FlyoutTheme.Dark:
var darkTheme = windowTheme.BaseColorScheme == ThemeManager.BaseColorDark ? windowTheme : ThemeManager.Current.GetInverseTheme(windowTheme);
if (darkTheme is null)
{
throw new InvalidOperationException("The Dark Flyout theme only works if the window theme abides the naming convention. " +
"See ThemeManager.GetInverseAppTheme for more infos");
}
ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, darkTheme);
break;
case FlyoutTheme.Light:
var lightTheme = windowTheme.BaseColorScheme == ThemeManager.BaseColorLight ? windowTheme : ThemeManager.Current.GetInverseTheme(windowTheme);
if (lightTheme is null)
{
throw new InvalidOperationException("The Light Flyout theme only works if the window theme abides the naming convention. " +
"See ThemeManager.GetInverseAppTheme for more infos");
}
ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, lightTheme);
break;
}
}
private void UpdateOpacityChange()
{
if (this.flyoutRoot is null || this.fadeOutFrame is null || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
{
return;
}
if (!this.AnimateOpacity)
{
this.fadeOutFrame.Value = 1;View on GitHub (pinned to 72099e310b)
Solutions
- Register a light counterpart theme following the naming convention.
- Use Flyout.Theme=Adapt to inherit the window theme without needing an inverse.
- Use built-in MahApps themes which provide both variants.
- Pre-check ThemeManager.Current.GetInverseTheme and fall back if null.
Defensive patterns
Strategy: validation
Validate before calling
var windowTheme = ThemeManager.Current.DetectTheme(window);
FlyoutTheme desired = FlyoutTheme.Light;
if (windowTheme is not null
&& windowTheme.BaseColorScheme != ThemeManager.BaseColorLight
&& ThemeManager.Current.GetInverseTheme(windowTheme) is null)
{
desired = FlyoutTheme.Adapt; // no light counterpart available
}
flyout.Theme = desired; Try / catch
try { flyout.Theme = FlyoutTheme.Light; }
catch (InvalidOperationException ex) when (ex.Message.Contains("Light Flyout theme"))
{
flyout.Theme = FlyoutTheme.Adapt;
} Prevention
- Register a light counterpart theme following the naming convention.
- Pre-check GetInverseTheme for light resolution.
- Fall back to Adapt when no light variant exists.
When it happens
Trigger: Setting Flyout.Theme=Light on a dark-themed window whose custom theme name lacks the Light/Dark convention; the light inverse variant was never registered.
Common situations: Custom dark theme registered without a light counterpart; non-conventional theme naming; incomplete theme resource pack.
Related errors
- The inverse Flyout theme only works if the window theme abid
- The Dark Flyout theme only works if the window theme abides
- {nameof(AutoWatermarkProperty)} is not supported for {fe.Get
- The property 'IsSpellCheckContextMenuEnabled' may only be se
- The settings file '{filename ?? "<unknown>"}' seems to be co
AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13).
Data as JSON: /api/errors/c42daf4d04b13ab2.
Report an issue: GitHub.