From fbf6a13f9256dd0e3506f5d4e325289ffbc579af Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sun, 5 Oct 2025 09:16:36 +0800 Subject: [PATCH] =?UTF-8?q?improve:=E4=B8=BB=E9=A2=98=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow_cs/MW_AutoTheme.cs | 31 +++++++++++++++++++ .../Windows/CountdownTimerWindow.xaml.cs | 19 ++++++++++++ Ink Canvas/Windows/RandWindow.xaml.cs | 19 ++++++++++++ 3 files changed, 69 insertions(+) diff --git a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs index dc93e2e2..c7755caf 100644 --- a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs +++ b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs @@ -74,6 +74,9 @@ namespace Ink_Canvas // 强制刷新UI window.InvalidateVisual(); + + // 通知其他窗口刷新主题 + RefreshOtherWindowsTheme(); } else if (theme == "Dark") { @@ -115,6 +118,9 @@ namespace Ink_Canvas // 强制刷新UI window.InvalidateVisual(); + + // 通知其他窗口刷新主题 + RefreshOtherWindowsTheme(); } } @@ -485,5 +491,30 @@ namespace Ink_Canvas // 忽略异常 } } + + /// + /// 刷新其他窗口的主题 + /// + private void RefreshOtherWindowsTheme() + { + try + { + // 刷新所有打开的计时器窗口 + foreach (Window window in Application.Current.Windows) + { + if (window is CountdownTimerWindow timerWindow) + { + timerWindow.RefreshTheme(); + } + else if (window is RandWindow randWindow) + { + randWindow.RefreshTheme(); + } + } + } + catch (Exception) + { + } + } } } \ No newline at end of file diff --git a/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs b/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs index 4f662605..545ea002 100644 --- a/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs +++ b/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs @@ -430,6 +430,25 @@ namespace Ink_Canvas InitializeUI(); } + /// + /// 刷新主题,当主窗口主题切换时调用 + /// + public void RefreshTheme() + { + try + { + // 重新应用主题 + ApplyTheme(); + + // 强制刷新UI + InvalidateVisual(); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"刷新计时器窗口主题出错: {ex.Message}", LogHelper.LogType.Error); + } + } + private void UpdateButtonTexts() { if (useLegacyUI) diff --git a/Ink Canvas/Windows/RandWindow.xaml.cs b/Ink Canvas/Windows/RandWindow.xaml.cs index f4b670aa..fc16446c 100644 --- a/Ink Canvas/Windows/RandWindow.xaml.cs +++ b/Ink Canvas/Windows/RandWindow.xaml.cs @@ -478,6 +478,25 @@ namespace Ink_Canvas // 这里可以添加必要的清理代码 } + /// + /// 刷新主题,当主窗口主题切换时调用 + /// + public void RefreshTheme() + { + try + { + // 重新应用主题 + ApplyTheme(MainWindow.Settings); + + // 强制刷新UI + InvalidateVisual(); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"刷新点名窗口主题出错: {ex.Message}", LogHelper.LogType.Error); + } + } + #region Win32 API 声明 [DllImport("user32.dll")] private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);