{"record":{"id":"50885d0f4f607b4b","repo":"MahApps/MahApps.Metro","slug":"the-inverse-dialog-theme-only-works-if-the-window","errorCode":null,"errorMessage":"The inverse dialog theme only works if the window theme abides the naming convention. See ThemeManager.GetInverseAppTheme for more infos","messagePattern":"The inverse dialog theme only works if the window theme abides the naming convention\\. See ThemeManager\\.GetInverseAppTheme for more infos","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs","lineNumber":377,"sourceCode":"            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)\n                || theme is null)\n            {\n                return;\n            }\n\n            switch (this.DialogSettings.ColorScheme)\n            {\n                case MetroDialogColorScheme.Theme:\n                    ThemeManager.Current.ChangeTheme(this, this.Resources, theme);\n                    this.SetCurrentValue(BackgroundProperty, TryGetResource(theme, \"MahApps.Brushes.Dialog.Background\"));\n                    this.SetCurrentValue(ForegroundProperty, TryGetResource(theme, \"MahApps.Brushes.Dialog.Foreground\"));\n                    break;\n\n                case MetroDialogColorScheme.Inverted:\n                    theme = ThemeManager.Current.GetInverseTheme(theme);\n                    if (theme is null)\n                    {\n                        throw new InvalidOperationException(\"The inverse dialog theme only works if the window theme abides the naming convention. \" +\n                                                            \"See ThemeManager.GetInverseAppTheme for more infos\");\n                    }\n\n                    ThemeManager.Current.ChangeTheme(this, this.Resources, theme);\n                    this.SetCurrentValue(BackgroundProperty, TryGetResource(theme, \"MahApps.Brushes.Dialog.Background\"));\n                    this.SetCurrentValue(ForegroundProperty, TryGetResource(theme, \"MahApps.Brushes.Dialog.Foreground\"));\n                    break;\n\n                case MetroDialogColorScheme.Accented:\n                    ThemeManager.Current.ChangeTheme(this, this.Resources, theme);\n                    this.SetCurrentValue(BackgroundProperty, TryGetResource(theme, \"MahApps.Brushes.Dialog.Background.Accent\"));\n                    this.SetCurrentValue(ForegroundProperty, TryGetResource(theme, \"MahApps.Brushes.Dialog.Foreground.Accent\"));\n                    break;\n            }\n        }\n\n        /// <summary>\n        /// This is called in the loaded event.","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs#L359-L395","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Register both Light and Dark counterpart themes using the standard naming (e.g. 'MyAccent (Light)' and 'MyAccent (Dark)') so GetInverseTheme can pair them.","Avoid MetroDialogColorScheme.Inverted for dialogs shown under a custom theme that lacks a Light/Dark counterpart; use MetroDialogColorScheme.Theme or Accented instead.","Ensure the owning MetroWindow has a detectable theme via ThemeManager.Current.DetectTheme before showing an inverted dialog.","Upgrade ControlzEx/MahApps so the theme catalog contains properly paired themes."],"exampleFix":"// before: custom theme breaks inverse lookup\nThemeManager.Current.AddTheme(new Theme(\"MyAccent\", \"MyAccent\", \"MyAccent\", Colors.Steel, Colors.White));\ndialog.DialogSettings.ColorScheme = MetroDialogColorScheme.Inverted; // throws\n// after: register paired Light/Dark themes\nThemeManager.Current.AddTheme(new Theme(\"Steel (Light)\", \"Steel\", \"Light\", ...));\nThemeManager.Current.AddTheme(new Theme(\"Steel (Dark)\",  \"Steel\", \"Dark\",  ...));","handlingStrategy":"validation","validationCode":"// Before showing an inverted dialog, ensure an inverse theme exists\nvar current = ThemeManager.Current.DetectTheme(dialog);\nvar inverse = current is null ? null : ThemeManager.Current.GetInverseTheme(current);\nif (inverse is null) {\n    // fall back to non-inverted scheme instead of throwing\ndialog.DialogSettings.ColorScheme = MetroDialogColorScheme.Theme;\n}","typeGuard":null,"tryCatchPattern":"try {\n    await coord.ShowMetroDialogAsync(context, dialog); // ColorScheme.Inverted\n} catch (InvalidOperationException ex) when (ex.Message.Contains(\"inverse dialog theme\")) {\n    dialog.DialogSettings.ColorScheme = MetroDialogColorScheme.Theme;\n    await coord.ShowMetroDialogAsync(context, dialog);\n}","preventionTips":["Register themes in paired 'Accent (Light)' / 'Accent (Dark)' form so GetInverseTheme can match.","Verify ThemeManager.Current.GetInverseTheme(theme) returns non-null before enabling Inverted dialogs.","Prefer MetroDialogColorScheme.Theme or Accented when custom themes lack a Light/Dark counterpart.","Ensure the owning MetroWindow has a detectable theme before showing inverted dialogs."],"tags":["wpf","theming","dialog","theme-manager","runtime"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}