{"record":{"id":"20e6b6c5895df6e0","repo":"MahApps/MahApps.Metro","slug":"the-dark-flyout-theme-only-works-if-the-window-the","errorCode":null,"errorMessage":"The Dark Flyout theme only works if the window theme abides the naming convention. See ThemeManager.GetInverseAppTheme for more infos","messagePattern":"The Dark Flyout 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/Flyout.cs","lineNumber":703,"sourceCode":"                    ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, windowTheme);\n                    break;\n\n                case FlyoutTheme.Inverse:\n                    var inverseTheme = ThemeManager.Current.GetInverseTheme(windowTheme);\n                    if (inverseTheme is null)\n                    {\n                        throw new InvalidOperationException(\"The inverse Flyout theme only works if the window theme abides the naming convention. \" +\n                                                            \"See ThemeManager.GetInverseAppTheme for more infos\");\n                    }\n\n                    ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, inverseTheme);\n                    break;\n\n                case FlyoutTheme.Dark:\n                    var darkTheme = windowTheme.BaseColorScheme == ThemeManager.BaseColorDark ? windowTheme : ThemeManager.Current.GetInverseTheme(windowTheme);\n                    if (darkTheme is null)\n                    {\n                        throw new InvalidOperationException(\"The Dark Flyout theme only works if the window theme abides the naming convention. \" +\n                                                            \"See ThemeManager.GetInverseAppTheme for more infos\");\n                    }\n\n                    ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, darkTheme);\n                    break;\n\n                case FlyoutTheme.Light:\n                    var lightTheme = windowTheme.BaseColorScheme == ThemeManager.BaseColorLight ? windowTheme : ThemeManager.Current.GetInverseTheme(windowTheme);\n                    if (lightTheme is null)\n                    {\n                        throw new InvalidOperationException(\"The Light Flyout theme only works if the window theme abides the naming convention. \" +\n                                                            \"See ThemeManager.GetInverseAppTheme for more infos\");\n                    }\n\n                    ThemeManager.Current.ApplyThemeResourcesFromTheme(this.Resources, lightTheme);\n                    break;\n            }\n        }","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/Flyout.cs#L685-L721","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom theme registered without a matching dark counterpart; theme resource dictionary renamed; only one base-color variant of a custom theme exists.","solutions":["Register a dark counterpart theme following the naming convention so GetInverseTheme resolves it.","Switch Flyout.Theme to Adapt to inherit the window theme directly.","Use a built-in MahApps theme which ships both Light and Dark variants.","Pre-check ThemeManager.Current.GetInverseTheme(windowTheme) and fall back to Adapt if null."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var windowTheme = ThemeManager.Current.DetectTheme(window);\nFlyoutTheme desired = FlyoutTheme.Dark;\n\nif (windowTheme is not null\n    && windowTheme.BaseColorScheme != ThemeManager.BaseColorDark\n    && ThemeManager.Current.GetInverseTheme(windowTheme) is null)\n{\n    desired = FlyoutTheme.Adapt; // no dark counterpart available\n}\nflyout.Theme = desired;","typeGuard":null,"tryCatchPattern":"try { flyout.Theme = FlyoutTheme.Dark; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Dark Flyout theme\"))\n{\n    flyout.Theme = FlyoutTheme.Adapt;\n}","preventionTips":["Register a dark counterpart theme following the naming convention.","Pre-check GetInverseTheme for dark resolution.","Fall back to Adapt when no dark variant exists."],"tags":["wpf","theming","mahapps","flyout","configuration"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}