diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs index 49620b6c..24b17713 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs @@ -1,7 +1,9 @@ using System; +using System; using System.Windows; using System.Windows.Controls; using Ink_Canvas.Windows.SettingsViews; +using System.Windows.Media; namespace Ink_Canvas.Windows.SettingsViews { @@ -90,19 +92,17 @@ namespace Ink_Canvas.Windows.SettingsViews { try { - var border = FindName(name) as System.Windows.Controls.Border; - if (border != null) + var border = FindName(name) as Border; + if (border == null) return; + + border.Background = isOn + ? new SolidColorBrush(Color.FromRgb(0x35, 0x84, 0xE4)) + : new SolidColorBrush(Color.FromRgb(0xE1, 0xE1, 0xE1)); + + var innerBorder = border.Child as Border; + if (innerBorder != null) { - bool currentState = border.Background.ToString().Contains("3584e4"); - if (currentState != isOn) - { - border.Background = isOn ? new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0x35, 0x84, 0xe4)) : new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0xe1, 0xe1, 0xe1)); - var innerBorder = border.Child as System.Windows.Controls.Border; - if (innerBorder != null) - { - innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; - } - } + innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; } } catch (Exception ex) @@ -111,6 +111,27 @@ namespace Ink_Canvas.Windows.SettingsViews } } + private static bool IsToggleSwitchOn(Border border) + { + try + { + if (border?.Background is SolidColorBrush scb) + { + return scb.Color.A == 0xFF && + scb.Color.R == 0x35 && + scb.Color.G == 0x84 && + scb.Color.B == 0xE4; + } + + var s = border?.Background?.ToString(); + return string.Equals(s, "#FF3584E4", StringComparison.OrdinalIgnoreCase); + } + catch + { + return false; + } + } + /// /// ToggleSwitch 点击事件处理 /// @@ -118,11 +139,10 @@ namespace Ink_Canvas.Windows.SettingsViews { if (!_isLoaded) return; - var border = sender as System.Windows.Controls.Border; + var border = sender as Border; if (border == null) return; - bool currentState = border.Background.ToString().Contains("3584e4"); - bool newState = !currentState; + bool newState = !IsToggleSwitchOn(border); SetToggleSwitchState(border.Name, newState); // 通过 MainWindowSettingsHelper 调用 MainWindow 中的方法