using Telerik.WinControls; namespace Pilz.UI.Telerik.Theming; public static class ThemeHelper { [Obsolete()] public static void ApplyApplicationTheme(ApplicationTheme theme, Func getLightTheme, Func getDarkTheme) { ApplyApplicationTheme(theme, getLightTheme, getDarkTheme, getDarkTheme); } [Obsolete()] public static void ApplyApplicationTheme(ApplicationTheme theme, Func getLightTheme, Func getDarkTheme, Func getGrayTheme) { ApplyApplicationTheme(new(theme, HighContrastMode.Auto), def => def.Theme switch { ApplicationTheme.Light => getLightTheme(), ApplicationTheme.Dark => getDarkTheme(), ApplicationTheme.Gray => getGrayTheme(), _ => throw new NotImplementedException(), }); } public static void ApplyApplicationTheme(ThemeDefinition themeDefinition, Func getTheme) { ThemeResolutionService.ApplicationThemeName = GetThemeName(themeDefinition, getTheme).ThemeName; } public static RadThemeComponentBase GetThemeName(ThemeDefinition themeDefinition, Func getTheme) { ApplicationTheme themeToUse; HighContrastMode highContrast; if (themeDefinition.HighContrast == HighContrastMode.Enable || themeDefinition.HighContrast == HighContrastMode.Auto && SystemInformation.HighContrast) highContrast = HighContrastMode.Enable; else highContrast = HighContrastMode.Disable; if (themeDefinition.Theme == ApplicationTheme.Light || themeDefinition.Theme == ApplicationTheme.Auto && WindowsSettings.AppsUseLightTheme) themeToUse = ApplicationTheme.Light; else if (themeDefinition.Theme == ApplicationTheme.Dark || themeDefinition.Theme == ApplicationTheme.Auto && !WindowsSettings.AppsUseLightTheme) themeToUse = ApplicationTheme.Dark; else themeToUse = ApplicationTheme.Gray; return getTheme(new(themeToUse, highContrast)); } public static bool IsDarkTheme(ApplicationTheme theme) { return theme == ApplicationTheme.Dark || theme == ApplicationTheme.Gray || theme == ApplicationTheme.Auto && !WindowsSettings.AppsUseLightTheme; } public static bool IsHighContrast(HighContrastMode theme) { return theme == HighContrastMode.Enable || theme == HighContrastMode.Auto && SystemInformation.HighContrast; } }