MahApps/MahApps.Metro · error · InvalidOperationException

The inverse dialog theme only works if the window theme abid

Error message

The inverse dialog theme only works if the window theme abides the naming convention. See ThemeManager.GetInverseAppTheme for more infos

What it means

When a dialog's DialogSettings.ColorScheme is Inverted, BaseMetroDialog asks ThemeManager.GetInverseTheme for the opposite of the current theme. The inverse lookup relies on ControlzEx theme naming: it swaps 'Light'/'Dark' in the theme name. If the current theme name does not match that convention (no Light/Dark token), GetInverseTheme returns null and the dialog throws InvalidOperationException. This only happens for the Inverted color scheme path.

Source

Thrown at src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs:377

            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)
                || theme is null)
            {
                return;
            }

            switch (this.DialogSettings.ColorScheme)
            {
                case MetroDialogColorScheme.Theme:
                    ThemeManager.Current.ChangeTheme(this, this.Resources, theme);
                    this.SetCurrentValue(BackgroundProperty, TryGetResource(theme, "MahApps.Brushes.Dialog.Background"));
                    this.SetCurrentValue(ForegroundProperty, TryGetResource(theme, "MahApps.Brushes.Dialog.Foreground"));
                    break;

                case MetroDialogColorScheme.Inverted:
                    theme = ThemeManager.Current.GetInverseTheme(theme);
                    if (theme is null)
                    {
                        throw new InvalidOperationException("The inverse dialog theme only works if the window theme abides the naming convention. " +
                                                            "See ThemeManager.GetInverseAppTheme for more infos");
                    }

                    ThemeManager.Current.ChangeTheme(this, this.Resources, theme);
                    this.SetCurrentValue(BackgroundProperty, TryGetResource(theme, "MahApps.Brushes.Dialog.Background"));
                    this.SetCurrentValue(ForegroundProperty, TryGetResource(theme, "MahApps.Brushes.Dialog.Foreground"));
                    break;

                case MetroDialogColorScheme.Accented:
                    ThemeManager.Current.ChangeTheme(this, this.Resources, theme);
                    this.SetCurrentValue(BackgroundProperty, TryGetResource(theme, "MahApps.Brushes.Dialog.Background.Accent"));
                    this.SetCurrentValue(ForegroundProperty, TryGetResource(theme, "MahApps.Brushes.Dialog.Foreground.Accent"));
                    break;
            }
        }

        /// <summary>
        /// This is called in the loaded event.

View on GitHub (pinned to 72099e310b)

Solutions

  1. Register both Light and Dark counterpart themes using the standard naming (e.g. 'MyAccent (Light)' and 'MyAccent (Dark)') so GetInverseTheme can pair them.
  2. Avoid MetroDialogColorScheme.Inverted for dialogs shown under a custom theme that lacks a Light/Dark counterpart; use MetroDialogColorScheme.Theme or Accented instead.
  3. Ensure the owning MetroWindow has a detectable theme via ThemeManager.Current.DetectTheme before showing an inverted dialog.
  4. Upgrade ControlzEx/MahApps so the theme catalog contains properly paired themes.

Example fix

// before: custom theme breaks inverse lookup
ThemeManager.Current.AddTheme(new Theme("MyAccent", "MyAccent", "MyAccent", Colors.Steel, Colors.White));
dialog.DialogSettings.ColorScheme = MetroDialogColorScheme.Inverted; // throws
// after: register paired Light/Dark themes
ThemeManager.Current.AddTheme(new Theme("Steel (Light)", "Steel", "Light", ...));
ThemeManager.Current.AddTheme(new Theme("Steel (Dark)",  "Steel", "Dark",  ...));
Defensive patterns

Strategy: validation

Validate before calling

// Before showing an inverted dialog, ensure an inverse theme exists
var current = ThemeManager.Current.DetectTheme(dialog);
var inverse = current is null ? null : ThemeManager.Current.GetInverseTheme(current);
if (inverse is null) {
    // fall back to non-inverted scheme instead of throwing
dialog.DialogSettings.ColorScheme = MetroDialogColorScheme.Theme;
}

Try / catch

try {
    await coord.ShowMetroDialogAsync(context, dialog); // ColorScheme.Inverted
} catch (InvalidOperationException ex) when (ex.Message.Contains("inverse dialog theme")) {
    dialog.DialogSettings.ColorScheme = MetroDialogColorScheme.Theme;
    await coord.ShowMetroDialogAsync(context, dialog);
}

Prevention

When it happens

Trigger: MetroDialogColorScheme.Inverted is set and the currently applied theme's name does not contain the expected 'Light'/'Dark' token pair (e.g. a custom theme named 'MyAccent' without '(Light)'/'(Dark)'), so ThemeManager.Current.GetInverseTheme(theme) returns null and the switch case throws.

Common situations: App registered a custom theme that skips the standard 'Accent (Light)'/'Accent (Dark)' naming. Theme was renamed. A theme from an older MahApps/ControlzEx version whose name format predates the convention. Using Inverted dialogs without ensuring both Light and Dark counterparts exist.

Related errors


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