{"record":{"id":"fc67783871deb248","repo":"MahApps/MahApps.Metro","slug":"the-inverse-flyout-theme-only-works-if-the-window","errorCode":null,"errorMessage":"The inverse Flyout theme only works if the window theme abides the naming convention. See ThemeManager.GetInverseAppTheme for more infos","messagePattern":"The inverse 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":692,"sourceCode":"\n        internal void ChangeFlyoutTheme(ControlzEx.Theming.Theme windowTheme)\n        {\n            if (windowTheme == ThemeManager.Current.DetectTheme(this.Resources))\n            {\n                return;\n            }\n\n            switch (this.Theme)\n            {\n                case FlyoutTheme.Adapt:\n                    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:","sourceCodeStart":674,"sourceCodeEnd":710,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/Flyout.cs#L674-L710","documentation":"Thrown by Flyout.ChangeFlyoutTheme when Theme==FlyoutTheme.Inverse and ThemeManager.GetInverseTheme(windowTheme) returns null. GetInverseTheme derives the opposite base-color theme by name convention: the window theme name must contain 'Light' or 'Dark' so the inverse can be resolved. A null result means the active window theme name does not follow this convention (e.g. a custom theme registered with an unconventional name).","triggerScenarios":"Setting Flyout.Theme=Inverse on a window whose theme was registered with a name lacking Light/Dark; using a custom app theme added via ThemeManager with a non-conventional name; renaming a built-in theme resource.","commonSituations":"Registering a custom theme with ThemeManager.Current.AddTheme whose key omits the .Light/.Dark suffix; loading theme resource dictionaries that don't follow the MahApps naming pattern; version upgrades where theme keys changed.","solutions":["Register custom themes with names containing 'Light' or 'Dark' (e.g. 'MyAccent.Dark', 'MyAccent.Light') so GetInverseTheme can resolve the counterpart.","Switch the Flyout.Theme from Inverse to Adapt, which uses the window theme directly without needing an inverse.","Use a built-in MahApps theme which already follows the naming convention.","Verify with ThemeManager.Current.GetInverseTheme(theme) at startup and fall back to Adapt if null."],"exampleFix":"// before - custom theme with non-conventional name\nvar dict = new ResourceDictionary { Source = new Uri(\"pack://.../MyAccent.xaml\") };\nThemeManager.Current.AddTheme(dict); // name has no Light/Dark\n\n// after - provide both Light and Dark variants following the convention\nThemeManager.Current.AddTheme(new ResourceDictionary { Source = new Uri(\"pack://.../MyAccent.Light.xaml\") });\nThemeManager.Current.AddTheme(new ResourceDictionary { Source = new Uri(\"pack://.../MyAccent.Dark.xaml\") });","handlingStrategy":"validation","validationCode":"// Resolve the inverse theme at startup; fall back to Adapt if unavailable.\nvar windowTheme = ThemeManager.Current.DetectTheme(window);\nvar inverse = windowTheme is null ? null : ThemeManager.Current.GetInverseTheme(windowTheme);\n\nflyout.Theme = inverse is null ? FlyoutTheme.Adapt : FlyoutTheme.Inverse;","typeGuard":null,"tryCatchPattern":"try { /* let ChangeFlyoutTheme run with Theme=Inverse */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"inverse Flyout theme\"))\n{\n    flyout.Theme = FlyoutTheme.Adapt; // fallback\n}","preventionTips":["Register custom themes with names containing 'Light' or 'Dark' so GetInverseTheme resolves.","Provide both base-color variants of any custom theme.","Pre-check GetInverseTheme and prefer Adapt when null."],"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"}