From dda0c2efee1a407da44ae71763fedc59a4396c04 Mon Sep 17 00:00:00 2001 From: Space Time Date: Sat, 7 Dec 2024 22:40:17 +0800 Subject: [PATCH] =?UTF-8?q?1.1.3=20->=201.1.4=20=E7=AC=AC36=E6=AC=A1?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.xaml.cs | 18 +++++++++++++----- Preses/SettingsPres.cs | 12 ++++++------ Wins/MainWin.xaml.cs | 7 +++---- Wins/SettingsWin.xaml.cs | 8 ++++---- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index f8a878d..e70f9f1 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,4 +1,6 @@ -using System.Windows; +using System; +using System.Windows; +using System.Windows.Controls; using System.Windows.Media; using System.Windows.Threading; using MaterialDesignThemes.Wpf; @@ -22,12 +24,18 @@ public partial class App : Application newTheme.SetPrimaryColor(Color.FromRgb(newColor.R, newColor.G, newColor.B)); paletteHelper.SetTheme(newTheme); + if (Environment.OSVersion.Version.Major == 10 && Environment.OSVersion.Version.Build < 22000) + { + Style newWindowStyle = new(typeof(Window), Current.Resources["CommonWindow"] as Style); + newWindowStyle.Setters.Add(new Setter(Window.BackgroundProperty, new DynamicResourceExtension("MaterialDesignBackground"))); + Current.Resources["CommonWindow"] = newWindowStyle; + } + Color? foregroundColor = ForegroundGenerator.GetForeground(newColor.R, newColor.G, newColor.B); - if (foregroundColor.HasValue) - Current.Resources["MaterialDesignBackground"] = new SolidColorBrush(foregroundColor.Value); - else - Current.Resources.Remove("MaterialDesignBackground"); + Style newButtonStyle = new(typeof(Button), Current.Resources[typeof(Button)] as Style); + newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, foregroundColor.HasValue ? new SolidColorBrush(foregroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground"))); + Current.Resources[typeof(Button)] = newButtonStyle; new MainWin(e.Args).Show(); } diff --git a/Preses/SettingsPres.cs b/Preses/SettingsPres.cs index 5689fbd..29a675a 100644 --- a/Preses/SettingsPres.cs +++ b/Preses/SettingsPres.cs @@ -51,13 +51,13 @@ internal partial class SettingsPres : GlobalPres { FontWeight newWeight = value.HasValue ? value.Value ? FontWeights.Light : FontWeights.Bold : FontWeights.Regular; - Style newStyle = new(typeof(Window), Application.Current.Resources["CommonWindow"] as Style); - newStyle.Setters.Add(new Setter(Window.FontWeightProperty, newWeight)); - Application.Current.Resources["CommonWindow"] = newStyle; + Style newWindowStyle = new(typeof(Window), Application.Current.Resources["CommonWindow"] as Style); + newWindowStyle.Setters.Add(new Setter(Window.FontWeightProperty, newWeight)); + Application.Current.Resources["CommonWindow"] = newWindowStyle; - newStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style); - newStyle.Setters.Add(new Setter(Button.FontWeightProperty, newWeight)); - Application.Current.Resources[typeof(Button)] = newStyle; + Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style); + newButtonStyle.Setters.Add(new Setter(Button.FontWeightProperty, newWeight)); + Application.Current.Resources[typeof(Button)] = newButtonStyle; Settings.Default.IsLightWeight = (sbyte)(value.HasValue ? value.Value ? 1 : 0 : -1); Settings.Default.Save(); diff --git a/Wins/MainWin.xaml.cs b/Wins/MainWin.xaml.cs index 3f0ecaa..f99f1df 100644 --- a/Wins/MainWin.xaml.cs +++ b/Wins/MainWin.xaml.cs @@ -470,10 +470,9 @@ public partial class MainWin : Window Color? foregroundColor = ForegroundGenerator.GetForeground(newColor.R, newColor.G, newColor.B); - if (foregroundColor.HasValue) - Application.Current.Resources["MaterialDesignBackground"] = new SolidColorBrush(foregroundColor.Value); - else - Application.Current.Resources.Remove("MaterialDesignBackground"); + Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style); + newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, foregroundColor.HasValue ? new SolidColorBrush(foregroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground"))); + Application.Current.Resources[typeof(Button)] = newButtonStyle; if (GameFlashInterval > 100) GameFlashInterval += random.Next(1, 4); diff --git a/Wins/SettingsWin.xaml.cs b/Wins/SettingsWin.xaml.cs index c085d63..ddaf23f 100644 --- a/Wins/SettingsWin.xaml.cs +++ b/Wins/SettingsWin.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Windows; +using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using MaterialDesignThemes.Wpf; @@ -46,10 +47,9 @@ public partial class SettingsWin : Window Color? foregroundColor = ForegroundGenerator.GetForeground(newColor.R, newColor.G, newColor.B); - if (foregroundColor.HasValue) - Application.Current.Resources["MaterialDesignBackground"] = new SolidColorBrush(foregroundColor.Value); - else - Application.Current.Resources.Remove("MaterialDesignBackground"); + Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style); + newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, foregroundColor.HasValue ? new SolidColorBrush(foregroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground"))); + Application.Current.Resources[typeof(Button)] = newButtonStyle; Settings.Default.PrimaryColor = System.Drawing.Color.FromArgb(newColor.A, newColor.R, newColor.G, newColor.B); Settings.Default.Save();