private void ChangeBaseColor(object sender, RoutedEventArgs e) { var clicked = e.OriginalSource as MenuItem; BaseColor baseColor = clicked.DataContext as BaseColor; ThemeManager.ChangeThemeBaseColor(Application.Current, baseColor.Name); }
private void Theme_L_D_Click(object sender, RoutedEventArgs e) { if (Properties.Settings.Default.BaseTheme == "Light") { ThemeManager.ChangeThemeBaseColor(System.Windows.Application.Current, "Dark"); Properties.Settings.Default.BaseTheme = "Dark"; } else { ThemeManager.ChangeThemeBaseColor(System.Windows.Application.Current, "Light"); Properties.Settings.Default.BaseTheme = "Light"; } Properties.Settings.Default.Save(); }
protected override void OnStartup(StartupEventArgs e) { SoftwareMutex.RunMutext(); GlobalData.Init(); #region 皮肤和样式载入 if (!string.IsNullOrEmpty(GlobalData.AppConfig.ColorSchemeName)) { ThemeManager.ChangeThemeColorScheme(this, GlobalData.AppConfig.ColorSchemeName); } if (!string.IsNullOrEmpty(GlobalData.AppConfig.ThemeName)) { ThemeManager.ChangeThemeBaseColor(this, GlobalData.AppConfig.ThemeName); } #endregion base.OnStartup(e); }
public void CreateDynamicAccentWithColorAndChangeBaseColorScheme() { var applicationTheme = ThemeManager.DetectTheme(Application.Current); Assert.That(() => ThemeHelper.CreateTheme("Dark", Colors.Red, Colors.Orange), Throws.Nothing); Assert.That(() => ThemeHelper.CreateTheme("Light", Colors.Red, Colors.Orange, changeImmediately: true), Throws.Nothing); var detected = ThemeManager.DetectTheme(Application.Current); Assert.NotNull(detected); Assert.That(detected.ColorScheme, Is.EqualTo(Colors.Red.ToString().Replace("#", string.Empty))); var newTheme = ThemeManager.ChangeThemeBaseColor(Application.Current, "Dark"); Assert.NotNull(newTheme); newTheme = ThemeManager.ChangeThemeBaseColor(Application.Current, "Light"); Assert.NotNull(newTheme); ThemeManager.ChangeTheme(Application.Current, applicationTheme); }
public void ChangeBaseColor() { { var currentTheme = ThemeManager.DetectTheme(Application.Current); Assert.That(currentTheme, Is.Not.Null); ThemeManager.ChangeThemeBaseColor(Application.Current, ThemeManager.GetInverseTheme(currentTheme).BaseColorScheme); Assert.That(ThemeManager.DetectTheme(Application.Current).BaseColorScheme, Is.Not.EqualTo(currentTheme.BaseColorScheme)); Assert.That(ThemeManager.DetectTheme(Application.Current).ColorScheme, Is.EqualTo(currentTheme.ColorScheme)); } { using (var window = new TestRibbonWindow()) { var currentTheme = ThemeManager.DetectTheme(window); Assert.That(currentTheme, Is.Not.Null); ThemeManager.ChangeThemeBaseColor(window, ThemeManager.GetInverseTheme(currentTheme).BaseColorScheme); Assert.That(ThemeManager.DetectTheme(window).BaseColorScheme, Is.Not.EqualTo(currentTheme.BaseColorScheme)); Assert.That(ThemeManager.DetectTheme(window).ColorScheme, Is.EqualTo(currentTheme.ColorScheme)); } } { var currentTheme = ThemeManager.DetectTheme(Application.Current); Assert.That(currentTheme, Is.Not.Null); var control = new Control(); ThemeManager.ChangeThemeBaseColor(control.Resources, currentTheme, ThemeManager.GetInverseTheme(currentTheme).BaseColorScheme); Assert.That(ThemeManager.DetectTheme(control.Resources).BaseColorScheme, Is.Not.EqualTo(currentTheme.BaseColorScheme)); Assert.That(ThemeManager.DetectTheme(control.Resources).ColorScheme, Is.EqualTo(currentTheme.ColorScheme)); } }
private void ChangeAppThemeButtonClick(object sender, RoutedEventArgs e) { ThemeManager.ChangeThemeBaseColor(Application.Current, ((Button) sender).Content.ToString()); Application.Current?.MainWindow?.Activate(); }
private void ChangeWindowThemeButtonClick(object sender, RoutedEventArgs e) { ThemeManager.ChangeThemeBaseColor(this, ((Button) sender).Content.ToString()); }
public void HighContrastScenarios() { var themeManager = new ThemeManager(); { var resource = new ResourceDictionary { { Theme.ThemeNameKey, "Theme 1" }, { Theme.ThemeDisplayNameKey, "Theme 1" }, { Theme.ThemeBaseColorSchemeKey, ThemeManager.BaseColorDark }, { Theme.ThemeColorSchemeKey, "Bar" }, { Theme.ThemePrimaryAccentColorKey, Colors.Blue }, { Theme.ThemeIsHighContrastKey, false } }; var newTheme = new Theme(new LibraryTheme(resource, null)); themeManager.AddTheme(newTheme); } { var resource = new ResourceDictionary { { Theme.ThemeNameKey, "Theme 2" }, { Theme.ThemeDisplayNameKey, "Theme 2" }, { Theme.ThemeBaseColorSchemeKey, ThemeManager.BaseColorLight }, { Theme.ThemeColorSchemeKey, "Bar" }, { Theme.ThemePrimaryAccentColorKey, Colors.Blue }, { Theme.ThemeIsHighContrastKey, false } }; var newTheme = new Theme(new LibraryTheme(resource, null)); themeManager.AddTheme(newTheme); } { var resource = new ResourceDictionary { { Theme.ThemeNameKey, "Theme 1" }, { Theme.ThemeDisplayNameKey, "Theme 1" }, { Theme.ThemeBaseColorSchemeKey, ThemeManager.BaseColorDark }, { Theme.ThemeColorSchemeKey, "Bar" }, { Theme.ThemePrimaryAccentColorKey, Colors.Blue }, { Theme.ThemeIsHighContrastKey, true } }; var newTheme = new Theme(new LibraryTheme(resource, null)); themeManager.AddTheme(newTheme); } { var resource = new ResourceDictionary { { Theme.ThemeNameKey, "Theme 2" }, { Theme.ThemeDisplayNameKey, "Theme 2" }, { Theme.ThemeBaseColorSchemeKey, ThemeManager.BaseColorLight }, { Theme.ThemeColorSchemeKey, "Bar" }, { Theme.ThemePrimaryAccentColorKey, Colors.Blue }, { Theme.ThemeIsHighContrastKey, true } }; var newTheme = new Theme(new LibraryTheme(resource, null)); themeManager.AddTheme(newTheme); } { var theme = themeManager.GetTheme(ThemeManager.BaseColorDark, "Bar"); Assert.That(theme, Is.Not.Null); Assert.That(theme.IsHighContrast, Is.False); } { var theme = themeManager.GetTheme(ThemeManager.BaseColorDark, "Bar", true); Assert.That(theme, Is.Not.Null); Assert.That(theme.IsHighContrast, Is.True); var inverseTheme = themeManager.GetInverseTheme(theme); Assert.That(inverseTheme, Is.Not.Null); Assert.That(inverseTheme, Is.Not.EqualTo(theme)); Assert.That(inverseTheme.IsHighContrast, Is.True); } { var frameworkElement = new FrameworkElement(); var theme = themeManager.GetTheme(ThemeManager.BaseColorDark, "Bar", true); var changeTheme = themeManager.ChangeTheme(frameworkElement, theme !); Assert.That(changeTheme, Is.EqualTo(theme)); var changeThemeBaseColor = themeManager.ChangeThemeBaseColor(frameworkElement, ThemeManager.BaseColorLight); Assert.That(changeThemeBaseColor, Is.Not.Null); Assert.That(changeThemeBaseColor, Is.Not.EqualTo(changeTheme)); Assert.That(changeThemeBaseColor.IsHighContrast, Is.True); } }
public void ApplyColorScheme(string baseColorName, ColorScheme colorScheme) { ThemeManager.ChangeThemeBaseColor(Application.Current, baseColorName); ThemeManager.ChangeThemeColorScheme(Application.Current, colorScheme.Name); }
/// <summary> /// Change the Theme /// </summary> protected override void DoChangeTheme() { ThemeManager.ChangeThemeBaseColor(Application.Current, this.Name); }
protected override void DoChangeTheme() { ThemeManager.ChangeThemeBaseColor(Application.Current, this.Name); GlobalData.AppConfig.ThemeName = this.Name; GlobalData.Save(); }