Skip to content

Instantly share code, notes, and snippets.

@Sandip124
Created May 25, 2022 13:53
Show Gist options
  • Save Sandip124/18f7b6d69f194b438d8bc2b198162558 to your computer and use it in GitHub Desktop.
Save Sandip124/18f7b6d69f194b438d8bc2b198162558 to your computer and use it in GitHub Desktop.
extension method to know windows has light mode or not.
/// <summary>
/// Determine whether it is a light theme
/// </summary>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public static bool IsLightTheme()
{
using (var personalizeKey =
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
false))
{
return (int) (personalizeKey?.GetValue("SystemUsesLightTheme", 0) ?? 0) == 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment