Skip to content

Commit

Permalink
(GH-3623) ThemeManager: Introduce ThemeType
Browse files Browse the repository at this point in the history
This enumeration helps us to check for light and dark themes.
  • Loading branch information
punker76 committed Oct 29, 2019
1 parent 85a5f78 commit 18b0d2a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/MahApps.Metro/ThemeManager/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ public Theme([NotNull] ResourceDictionary resourceDictionary)
this.BaseColorScheme = (string)this.Resources[ThemeBaseColorSchemeKey];
this.ColorScheme = (string)this.Resources[ThemeColorSchemeKey];
this.ShowcaseBrush = (SolidColorBrush)this.Resources[ThemeShowcaseBrushKey];
if (this.Name.StartsWith("light.", StringComparison.OrdinalIgnoreCase))
{
this.Type = ThemeType.Light;
}
else if (this.Name.StartsWith("dark.", StringComparison.OrdinalIgnoreCase))
{
this.Type = ThemeType.Dark;
}
}

/// <summary>
Expand All @@ -76,6 +84,11 @@ public Theme([NotNull] ResourceDictionary resourceDictionary)
/// </summary>
public string Name { get; }

/// <summary>
/// Gets the theme type (light, dark).
/// </summary>
public ThemeType Type { get; } = ThemeType.Unknown;

/// <summary>
/// Gets the display name of the theme.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/MahApps.Metro/ThemeManager/ThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ public static Theme GetInverseTheme([NotNull] Theme theme)
throw new ArgumentNullException(nameof(theme));
}

if (theme.Name.StartsWith("dark.", StringComparison.OrdinalIgnoreCase))
if (theme.Type == ThemeType.Dark)
{
return GetTheme("Light." + theme.Name.Substring("dark.".Length));
}

if (theme.Name.StartsWith("light.", StringComparison.OrdinalIgnoreCase))
if (theme.Type == ThemeType.Light)
{
return GetTheme("Dark." + theme.Name.Substring("light.".Length));
}
Expand Down
12 changes: 12 additions & 0 deletions src/MahApps.Metro/ThemeManager/ThemeType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace MahApps.Metro
{
/// <summary>
/// An Enum representing the theme type.
/// </summary>
public enum ThemeType
{
Unknown,
Light,
Dark
}
}

0 comments on commit 18b0d2a

Please sign in to comment.