diff --git a/Ink Canvas/Windows/SeewoStyleTimerWindow.xaml b/Ink Canvas/Windows/SeewoStyleTimerWindow.xaml index 738b12eb..fd4a0243 100644 --- a/Ink Canvas/Windows/SeewoStyleTimerWindow.xaml +++ b/Ink Canvas/Windows/SeewoStyleTimerWindow.xaml @@ -5,18 +5,11 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Ink_Canvas" xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" - ui:ThemeManager.RequestedTheme="Light" Topmost="True" Background="Transparent" + Topmost="True" Background="Transparent" mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True" Loaded="Window_Loaded" Closing="Window_Closing" WindowStartupLocation="CenterScreen" Title="Ink Canvas 画板 - 计时器" Height="400" Width="600"> - - - - - - - - + diff --git a/Ink Canvas/Windows/SeewoStyleTimerWindow.xaml.cs b/Ink Canvas/Windows/SeewoStyleTimerWindow.xaml.cs index de7d6fe2..e719f753 100644 --- a/Ink Canvas/Windows/SeewoStyleTimerWindow.xaml.cs +++ b/Ink Canvas/Windows/SeewoStyleTimerWindow.xaml.cs @@ -91,16 +91,10 @@ namespace Ink_Canvas { try { - // 根据主题设置数字显示颜色 - var digitForeground = Application.Current.FindResource("SeewoTimerWindowDigitForeground") as SolidColorBrush; - if (digitForeground != null) + // 应用主题设置 + if (MainWindow.Settings != null) { - Digit1Display.Foreground = digitForeground; - Digit2Display.Foreground = digitForeground; - Digit3Display.Foreground = digitForeground; - Digit4Display.Foreground = digitForeground; - Digit5Display.Foreground = digitForeground; - Digit6Display.Foreground = digitForeground; + ApplyTheme(MainWindow.Settings); } } catch (Exception ex) @@ -109,6 +103,62 @@ namespace Ink_Canvas } } + private void ApplyTheme(Settings settings) + { + try + { + if (settings.Appearance.Theme == 0) // 浅色主题 + { + iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Light); + } + else if (settings.Appearance.Theme == 1) // 深色主题 + { + iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Dark); + } + else // 跟随系统主题 + { + bool isSystemLight = IsSystemThemeLight(); + if (isSystemLight) + { + iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Light); + } + else + { + iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Dark); + } + } + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"应用仿希沃倒计时窗口主题出错: {ex.Message}", LogHelper.LogType.Error); + } + } + + private bool IsSystemThemeLight() + { + var light = false; + try + { + var registryKey = Microsoft.Win32.Registry.CurrentUser; + var themeKey = registryKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"); + if (themeKey != null) + { + var value = themeKey.GetValue("AppsUseLightTheme"); + if (value != null) + { + light = (int)value == 1; + } + themeKey.Close(); + } + } + catch + { + // 如果读取注册表失败,默认为浅色主题 + light = true; + } + return light; + } + private void UpdateDigitDisplays() { Digit1Display.Text = (hour / 10).ToString(); diff --git a/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache b/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache index c8c2dfbd..57d842b8 100644 Binary files a/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache and b/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache differ