From 22555b835b13d96b16855cdc7a7838588eceefab Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Fri, 6 Feb 2026 22:06:50 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SettingsViews/AdvancedPanel.xaml.cs | 3 +- .../SettingsViews/AutomationPanel.xaml.cs | 5 ++- .../SettingsViews/CanvasAndInkPanel.xaml.cs | 3 +- .../SettingsViews/GesturesPanel.xaml.cs | 3 +- .../SettingsViews/LuckyRandomPanel.xaml.cs | 3 +- .../SettingsViews/PowerPointPanel.xaml.cs | 3 +- .../SettingsViews/SettingsPanelBase.cs | 3 +- .../SettingsViews/SnapshotPanel.xaml.cs | 3 +- .../SettingsViews/StartupPanel.xaml.cs | 5 ++- .../SettingsViews/ThemeHelper.cs | 37 ++++++++++++++++++- .../SettingsViews/ThemePanel.xaml.cs | 3 +- 11 files changed, 58 insertions(+), 13 deletions(-) diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs index 1fa5d83c..4e552d6b 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs @@ -172,11 +172,12 @@ namespace Ink_Canvas.Windows.SettingsViews if (toggleSwitch == null) return; toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) - : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; + innerBorder.Background = new SolidColorBrush(Colors.White); } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs index 24b17713..4cd5190f 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs @@ -1,5 +1,4 @@ using System; -using System; using System.Windows; using System.Windows.Controls; using Ink_Canvas.Windows.SettingsViews; @@ -97,12 +96,14 @@ namespace Ink_Canvas.Windows.SettingsViews border.Background = isOn ? new SolidColorBrush(Color.FromRgb(0x35, 0x84, 0xE4)) - : new SolidColorBrush(Color.FromRgb(0xE1, 0xE1, 0xE1)); + : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(0xE1, 0xE1, 0xE1))); var innerBorder = border.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; + // 保持滑块为白色(主题切换时也更稳定) + innerBorder.Background = new SolidColorBrush(Colors.White); } } catch (Exception ex) diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml.cs index d2a9cb50..5e521781 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml.cs @@ -184,11 +184,12 @@ namespace Ink_Canvas.Windows.SettingsViews if (toggleSwitch == null) return; toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) - : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; + innerBorder.Background = new SolidColorBrush(Colors.White); } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml.cs index 5e71f8c2..914e46cd 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml.cs @@ -122,11 +122,12 @@ namespace Ink_Canvas.Windows.SettingsViews if (toggleSwitch == null) return; toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) - : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; + innerBorder.Background = new SolidColorBrush(Colors.White); } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml.cs index 64cdb4bc..1afb36fd 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml.cs @@ -169,11 +169,12 @@ namespace Ink_Canvas.Windows.SettingsViews if (toggleSwitch == null) return; toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) - : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; + innerBorder.Background = new SolidColorBrush(Colors.White); } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml.cs index be535ad7..e6717a12 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml.cs @@ -261,11 +261,12 @@ namespace Ink_Canvas.Windows.SettingsViews if (toggleSwitch == null) return; toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) - : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; + innerBorder.Background = new SolidColorBrush(Colors.White); } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/SettingsPanelBase.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/SettingsPanelBase.cs index 6f4db549..d90075f7 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/SettingsPanelBase.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/SettingsPanelBase.cs @@ -182,11 +182,12 @@ namespace Ink_Canvas.Windows.SettingsViews if (toggleSwitch == null) return; toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) - : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; + innerBorder.Background = new SolidColorBrush(Colors.White); } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs index 6d7f0dc8..8d32ee51 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs @@ -160,11 +160,12 @@ namespace Ink_Canvas.Windows.SettingsViews if (toggleSwitch == null) return; toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) - : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? System.Windows.HorizontalAlignment.Right : System.Windows.HorizontalAlignment.Left; + innerBorder.Background = new SolidColorBrush(Colors.White); } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs index f1fb8fc5..3b20bd37 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs @@ -222,11 +222,14 @@ namespace Ink_Canvas.Windows.SettingsViews private void SetToggleSwitchState(Border toggleSwitch, bool isOn) { if (toggleSwitch == null) return; - toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + toggleSwitch.Background = isOn + ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) + : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; + innerBorder.Background = new SolidColorBrush(Colors.White); } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs index 7bcedb6e..00bf5db6 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs @@ -8,6 +8,35 @@ namespace Ink_Canvas.Windows.SettingsViews /// public static class ThemeHelper { + private static bool IsToggleSwitchThumb(System.Windows.Controls.Border border) + { + try + { + if (border == null) return false; + + // ToggleSwitch thumb 常见尺寸:19x19,圆角 10,父级为 48x25 的开关背景 + if (border.Width < 16 || border.Width > 24 || border.Height < 16 || border.Height > 24) + return false; + + if (border.CornerRadius.TopLeft < 8) return false; + + if (border.Parent is System.Windows.Controls.Border parent) + { + if (parent.Width >= 40 && parent.Width <= 60 && + parent.Height >= 20 && parent.Height <= 35 && + parent.CornerRadius.TopLeft >= 10) + { + return true; + } + } + + return false; + } + catch + { + return false; + } + } /// /// 检查当前是否为深色主题 /// @@ -180,8 +209,12 @@ namespace Ink_Canvas.Windows.SettingsViews } else { - // 其他白色背景(如搜索框) - border.Background = GetTextBoxBackgroundBrush(); + // ToggleSwitch thumb 应保持白色,不参与主题背景替换 + if (!IsToggleSwitchThumb(border)) + { + // 其他白色背景(如搜索框) + border.Background = GetTextBoxBackgroundBrush(); + } } } else if (color.R == 250 && color.G == 250 && color.B == 250) // #fafafa - 主背景 diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs index 55b071f4..91433e21 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs @@ -230,11 +230,12 @@ namespace Ink_Canvas.Windows.SettingsViews if (toggleSwitch == null) return; toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) - : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; + innerBorder.Background = new SolidColorBrush(Colors.White); } }