-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theming for powertoys run #4007
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e66ec18
Removed Wox Theme Manager
dsrivastavv a376f25
Added Light and dark theme and template for high contrast theme
dsrivastavv 45c474b
Updated themeManager to remove strings
dsrivastavv 8a3982d
Fixed issue with high contrast theme not being applied
dsrivastavv 10734aa
Fixed formatting
dsrivastavv 2371524
Merge remote-tracking branch 'upstream/master' into somil55/WPFTheme
dsrivastavv cf3dee3
Merge remote-tracking branch 'upstream/master' into somil55/WPFTheme
dsrivastavv 978b0c1
Updated MSI to include dll for Mahapps and controlzex
dsrivastavv b21cec5
Added support for multiple high contrast themes
dsrivastavv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
using ControlzEx.Theming; | ||
using MahApps.Metro.Theming; | ||
using Microsoft.Win32; | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Windows; | ||
|
||
namespace Wox.Core.Resource | ||
{ | ||
public class ThemeManager | ||
{ | ||
private Theme currentTheme; | ||
private readonly Application App; | ||
private readonly string LightTheme = "Light.Accent1"; | ||
private readonly string DarkTheme = "Dark.Accent1"; | ||
private readonly string HighContrastOneTheme = "HighContrast.Accent2"; | ||
private readonly string HighContrastTwoTheme = "HighContrast.Accent3"; | ||
private readonly string HighContrastBlackTheme = "HighContrast.Accent4"; | ||
private readonly string HighContrastWhiteTheme = "HighContrast.Accent5"; | ||
|
||
public ThemeManager(Application app) | ||
{ | ||
this.App = app; | ||
|
||
Uri HighContrastOneThemeUri = new Uri("pack://application:,,,/Themes/HighContrast1.xaml"); | ||
Uri HighContrastTwoThemeUri = new Uri("pack://application:,,,/Themes/HighContrast2.xaml"); | ||
Uri HighContrastBlackThemeUri = new Uri("pack://application:,,,/Themes/HighContrastWhite.xaml"); | ||
Uri HighContrastWhiteThemeUri = new Uri("pack://application:,,,/Themes/HighContrastBlack.xaml"); | ||
Uri LightThemeUri = new Uri("pack://application:,,,/Themes/Light.xaml"); | ||
Uri DarkThemeUri = new Uri("pack://application:,,,/Themes/Dark.xaml"); | ||
|
||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( | ||
new LibraryTheme(HighContrastOneThemeUri, | ||
MahAppsLibraryThemeProvider.DefaultInstance)); | ||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( | ||
new LibraryTheme(HighContrastTwoThemeUri, | ||
MahAppsLibraryThemeProvider.DefaultInstance)); | ||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( | ||
new LibraryTheme(HighContrastBlackThemeUri, | ||
MahAppsLibraryThemeProvider.DefaultInstance)); | ||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( | ||
new LibraryTheme(HighContrastWhiteThemeUri, | ||
MahAppsLibraryThemeProvider.DefaultInstance)); | ||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( | ||
new LibraryTheme(LightThemeUri, | ||
MahAppsLibraryThemeProvider.DefaultInstance)); | ||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( | ||
new LibraryTheme(DarkThemeUri, | ||
MahAppsLibraryThemeProvider.DefaultInstance)); | ||
|
||
ResetTheme(); | ||
ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode; | ||
ControlzEx.Theming.ThemeManager.Current.ThemeChanged += Current_ThemeChanged; | ||
SystemParameters.StaticPropertyChanged += (sender, args) => | ||
{ | ||
if (args.PropertyName == nameof(SystemParameters.HighContrast)) | ||
{ | ||
ResetTheme(); | ||
} | ||
}; | ||
} | ||
|
||
|
||
public Theme GetHighContrastBaseType() | ||
{ | ||
string RegistryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes"; | ||
string theme = (string) Registry.GetValue(RegistryKey, "CurrentTheme", string.Empty); | ||
theme = theme.Split('\\').Last().Split('.').First().ToString(); | ||
|
||
if (theme == "hc1") | ||
return Theme.HighContrastOne; | ||
else if (theme == "hc2") | ||
return Theme.HighContrastTwo; | ||
else if (theme == "hcwhite") | ||
return Theme.HighContrastWhite; | ||
else if (theme == "hcblack") | ||
return Theme.HighContrastBlack; | ||
else | ||
return Theme.None; | ||
} | ||
|
||
public void ResetTheme() | ||
{ | ||
if (SystemParameters.HighContrast) | ||
{ | ||
Theme highContrastBaseType = GetHighContrastBaseType(); | ||
ChangeTheme(highContrastBaseType); | ||
} | ||
else | ||
{ | ||
string baseColor = WindowsThemeHelper.GetWindowsBaseColor(); | ||
ChangeTheme((Theme)Enum.Parse(typeof(Theme), baseColor)); | ||
} | ||
} | ||
|
||
private void ChangeTheme(Theme theme) | ||
{ | ||
if (theme == currentTheme) | ||
return; | ||
if (theme == Theme.HighContrastOne) | ||
{ | ||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.HighContrastOneTheme); | ||
currentTheme = Theme.HighContrastOne; | ||
} | ||
else if (theme == Theme.HighContrastTwo) | ||
{ | ||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.HighContrastTwoTheme); | ||
currentTheme = Theme.HighContrastTwo; | ||
} | ||
else if (theme == Theme.HighContrastWhite) | ||
{ | ||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.HighContrastWhiteTheme); | ||
currentTheme = Theme.HighContrastWhite; | ||
} | ||
else if (theme == Theme.HighContrastBlack) | ||
{ | ||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.HighContrastBlackTheme); | ||
currentTheme = Theme.HighContrastBlack; | ||
} | ||
else if (theme == Theme.Light) | ||
{ | ||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.LightTheme); | ||
currentTheme = Theme.Light; | ||
} | ||
else if (theme == Theme.Dark) | ||
{ | ||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.DarkTheme); | ||
currentTheme = Theme.Dark; | ||
} | ||
else | ||
{ | ||
currentTheme = Theme.None; | ||
} | ||
Debug.WriteLine("Theme Changed to :" + currentTheme); | ||
} | ||
|
||
private void Current_ThemeChanged(object sender, ThemeChangedEventArgs e) | ||
{ | ||
ResetTheme(); | ||
} | ||
} | ||
|
||
public enum Theme | ||
{ | ||
None, | ||
Light, | ||
Dark, | ||
HighContrastOne, | ||
HighContrastTwo, | ||
HighContrastBlack, | ||
HighContrastWhite, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the following dll's at the end: ControlzEx.dll, MahApps.Metro.dll