MahApps/MahApps.Metro · error · InvalidOperationException

The Dark Flyout theme only works if the window theme abides

Error message

The Dark 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.Dark and the needed dark theme cannot be resolved. If the window theme's BaseColorScheme is already Dark, the window theme itself is used (no error); otherwise GetInverseTheme is called to find the dark counterpart and returns null when the theme name doesn't follow the Light/Dark naming convention.

Source

Thrown at src/MahApps.Metro/Controls/Flyout.cs:703

                    ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, windowTheme);
                    break;

                case FlyoutTheme.Inverse:
                    var inverseTheme = ThemeManager.Current.GetInverseTheme(windowTheme);
                    if (inverseTheme is null)
                    {
                        throw new InvalidOperationException("The inverse Flyout theme only works if the window theme abides the naming convention. " +
                                                            "See ThemeManager.GetInverseAppTheme for more infos");
                    }

                    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;
            }
        }

View on GitHub (pinned to 72099e310b)

Solutions

  1. Register a dark counterpart theme following the naming convention so GetInverseTheme resolves it.
  2. Switch Flyout.Theme to Adapt to inherit the window theme directly.
  3. Use a built-in MahApps theme which ships both Light and Dark variants.
  4. Pre-check ThemeManager.Current.GetInverseTheme(windowTheme) and fall back to Adapt if null.
Defensive patterns

Strategy: validation

Validate before calling

var windowTheme = ThemeManager.Current.DetectTheme(window);
FlyoutTheme desired = FlyoutTheme.Dark;

if (windowTheme is not null
    && windowTheme.BaseColorScheme != ThemeManager.BaseColorDark
    && ThemeManager.Current.GetInverseTheme(windowTheme) is null)
{
    desired = FlyoutTheme.Adapt; // no dark counterpart available
}
flyout.Theme = desired;

Try / catch

try { flyout.Theme = FlyoutTheme.Dark; }
catch (InvalidOperationException ex) when (ex.Message.Contains("Dark Flyout theme"))
{
    flyout.Theme = FlyoutTheme.Adapt;
}

Prevention

When it happens

Trigger: Setting Flyout.Theme=Dark on a window with a light custom theme whose name lacks 'Light'/'Dark'; the inverse (dark) variant of the custom theme was never registered.

Common situations: Custom theme registered without a matching dark counterpart; theme resource dictionary renamed; only one base-color variant of a custom theme exists.

Related errors


AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13). Data as JSON: /api/errors/20e6b6c5895df6e0. Report an issue: GitHub.