From 4649649cf391b8793a455603bd76906a3f278219 Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sat, 10 Jan 2026 17:31:43 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"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 This reverts commit acafdcc991fe6db487293a6717e7fb5a8b0d3131. --- .../SettingsViews/AdvancedPanel.xaml.cs | 35 +-- .../SettingsViews/SnapshotPanel.xaml.cs | 3 +- .../SettingsViews/StartupPanel.xaml | 2 +- .../SettingsViews/StartupPanel.xaml.cs | 202 ++++----------- .../SettingsViews/ThemeHelper.cs | 4 +- .../SettingsViews/ThemePanel.xaml.cs | 233 +++++------------- .../SettingsViews/TimerPanel.xaml.cs | 2 +- 7 files changed, 127 insertions(+), 354 deletions(-) diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs index 3354a26e..e85bd430 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs @@ -483,18 +483,12 @@ namespace Ink_Canvas.Windows.SettingsViews if (isRegistered) { FileAssociationStatusText.Text = "✓ .icstk文件关联已注册"; - // 使用主题适配的绿色 - FileAssociationStatusText.Foreground = ThemeHelper.IsDarkTheme - ? new SolidColorBrush(Color.FromRgb(76, 175, 80)) // 深色主题下的绿色 - : new SolidColorBrush(Color.FromRgb(46, 125, 50)); // 浅色主题下的绿色 + FileAssociationStatusText.Foreground = new SolidColorBrush(Colors.LightGreen); } else { FileAssociationStatusText.Text = "✗ .icstk文件关联未注册"; - // 使用主题适配的红色 - FileAssociationStatusText.Foreground = ThemeHelper.IsDarkTheme - ? new SolidColorBrush(Color.FromRgb(244, 67, 54)) // 深色主题下的红色 - : new SolidColorBrush(Color.FromRgb(198, 40, 40)); // 浅色主题下的红色 + FileAssociationStatusText.Foreground = new SolidColorBrush(Colors.LightCoral); } } } @@ -504,10 +498,7 @@ namespace Ink_Canvas.Windows.SettingsViews { FileAssociationStatusText.Visibility = Visibility.Visible; FileAssociationStatusText.Text = $"✗ 检查文件关联状态时出错: {ex.Message}"; - // 使用主题适配的红色 - FileAssociationStatusText.Foreground = ThemeHelper.IsDarkTheme - ? new SolidColorBrush(Color.FromRgb(244, 67, 54)) // 深色主题下的红色 - : new SolidColorBrush(Color.FromRgb(198, 40, 40)); // 浅色主题下的红色 + FileAssociationStatusText.Foreground = new SolidColorBrush(Colors.LightCoral); } } } @@ -521,26 +512,6 @@ namespace Ink_Canvas.Windows.SettingsViews { SetOptionButtonState("AutoBackupInterval", MainWindow.Settings.Advanced.AutoBackupIntervalDays); } - - // 如果文件关联状态文本已显示,更新其颜色以适配主题 - if (FileAssociationStatusText != null && FileAssociationStatusText.Visibility == Visibility.Visible) - { - var currentText = FileAssociationStatusText.Text; - if (currentText.Contains("✓") || currentText.Contains("已注册")) - { - // 成功状态 - 绿色 - FileAssociationStatusText.Foreground = ThemeHelper.IsDarkTheme - ? new SolidColorBrush(Color.FromRgb(76, 175, 80)) - : new SolidColorBrush(Color.FromRgb(46, 125, 50)); - } - else if (currentText.Contains("✗") || currentText.Contains("未注册") || currentText.Contains("出错")) - { - // 错误状态 - 红色 - FileAssociationStatusText.Foreground = ThemeHelper.IsDarkTheme - ? new SolidColorBrush(Color.FromRgb(244, 67, 54)) - : new SolidColorBrush(Color.FromRgb(198, 40, 40)); - } - } } catch (Exception ex) { diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs index cbbeb49f..84ee798a 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Windows; using System.Windows.Controls; -using System.Windows.Input; using System.Windows.Media; using Application = System.Windows.Application; @@ -414,7 +413,7 @@ namespace Ink_Canvas.Windows.SettingsViews } } - private void AutoSaveIntervalButton_Click(object sender, MouseButtonEventArgs e) + private void AutoSaveIntervalButton_Click(object sender, RoutedEventArgs e) { if (!_isLoaded) return; diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml index dd7c5721..b03a97b4 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml @@ -123,7 +123,7 @@ - + diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs index 0403c705..4b90263d 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs @@ -1,4 +1,4 @@ -using Ink_Canvas; +using Ink_Canvas; using iNKORE.UI.WPF.Helpers; using System; using System.Linq; @@ -8,9 +8,6 @@ using System.Windows.Media; namespace Ink_Canvas.Windows.SettingsViews { - /// - /// StartupPanel.xaml 的交互逻辑 - /// public partial class StartupPanel : UserControl { private bool _isLoaded = false; @@ -24,21 +21,14 @@ namespace Ink_Canvas.Windows.SettingsViews private void StartupPanel_Loaded(object sender, RoutedEventArgs e) { LoadSettings(); - // 添加触摸支持 EnableTouchSupport(); - // 应用主题 ApplyTheme(); _isLoaded = true; } - - /// - /// 为面板中的所有交互控件启用触摸支持 - /// private void EnableTouchSupport() { try { - // 延迟执行,确保所有控件都已加载 Dispatcher.BeginInvoke(new Action(() => { EnableTouchSupportForControls(this); @@ -46,16 +36,11 @@ namespace Ink_Canvas.Windows.SettingsViews } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine($"StartupPanel 启用触摸支持时出错: {ex.Message}"); + System.Diagnostics.Debug.WriteLine($"StartupPanel 启用触摸支持时出�? {ex.Message}"); } } - - /// - /// 为控件树中的所有交互控件启用触摸支持 - /// private void EnableTouchSupportForControls(System.Windows.DependencyObject parent) { - // 使用 MainWindowSettingsHelper 的通用方法 MainWindowSettingsHelper.EnableTouchSupportForControls(parent); } @@ -74,10 +59,6 @@ namespace Ink_Canvas.Windows.SettingsViews IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs()); } } - - /// - /// 加载设置到UI - /// public void LoadSettings() { if (MainWindow.Settings == null) return; @@ -86,15 +67,12 @@ namespace Ink_Canvas.Windows.SettingsViews try { - // 自动更新设置 var toggleSwitchIsAutoUpdate = FindToggleSwitch("ToggleSwitchIsAutoUpdate"); if (toggleSwitchIsAutoUpdate != null) { bool isAutoUpdate = MainWindow.Settings.Startup.IsAutoUpdate; SetToggleSwitchState(toggleSwitchIsAutoUpdate, isAutoUpdate); } - - // 静默更新设置 var toggleSwitchIsAutoUpdateWithSilence = FindToggleSwitch("ToggleSwitchIsAutoUpdateWithSilence"); if (toggleSwitchIsAutoUpdateWithSilence != null) { @@ -102,17 +80,11 @@ namespace Ink_Canvas.Windows.SettingsViews SetToggleSwitchState(toggleSwitchIsAutoUpdateWithSilence, isAutoUpdateWithSilence); toggleSwitchIsAutoUpdateWithSilence.Visibility = MainWindow.Settings.Startup.IsAutoUpdate ? Visibility.Visible : Visibility.Collapsed; } - - // 静默更新时间段 - if (AutoUpdateTimePeriodBlock != null) { AutoUpdateTimePeriodBlock.Visibility = (MainWindow.Settings.Startup.IsAutoUpdateWithSilence && MainWindow.Settings.Startup.IsAutoUpdate) ? Visibility.Visible : Visibility.Collapsed; } - - // 设置时间选择器 - if (AutoUpdateWithSilenceStartTimeComboBox != null) { var startTime = MainWindow.Settings.Startup.AutoUpdateWithSilenceStartTime ?? "06:00"; var startItem = AutoUpdateWithSilenceStartTimeComboBox.Items.Cast() @@ -133,53 +105,38 @@ namespace Ink_Canvas.Windows.SettingsViews AutoUpdateWithSilenceEndTimeComboBox.SelectedItem = endItem; } } - - // 开机时运行 var toggleSwitchRunAtStartup = FindToggleSwitch("ToggleSwitchRunAtStartup"); if (toggleSwitchRunAtStartup != null) { - // 检查启动项是否存在 bool runAtStartup = System.IO.File.Exists( Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\Ink Canvas Annotation.lnk"); SetToggleSwitchState(toggleSwitchRunAtStartup, runAtStartup); } - - // 启动时折叠 var toggleSwitchFoldAtStartup = FindToggleSwitch("ToggleSwitchFoldAtStartup"); if (toggleSwitchFoldAtStartup != null) { SetToggleSwitchState(toggleSwitchFoldAtStartup, MainWindow.Settings.Startup.IsFoldAtStartup); } - - // 窗口无焦点模式 var toggleSwitchNoFocusMode = FindToggleSwitch("ToggleSwitchNoFocusMode"); if (toggleSwitchNoFocusMode != null && MainWindow.Settings.Advanced != null) { SetToggleSwitchState(toggleSwitchNoFocusMode, MainWindow.Settings.Advanced.IsNoFocusMode); } - - // 窗口无边框模式 var toggleSwitchWindowMode = FindToggleSwitch("ToggleSwitchWindowMode"); if (toggleSwitchWindowMode != null && MainWindow.Settings.Advanced != null) { SetToggleSwitchState(toggleSwitchWindowMode, MainWindow.Settings.Advanced.WindowMode); } - - // 窗口置顶 var toggleSwitchAlwaysOnTop = FindToggleSwitch("ToggleSwitchAlwaysOnTop"); if (toggleSwitchAlwaysOnTop != null && MainWindow.Settings.Advanced != null) { SetToggleSwitchState(toggleSwitchAlwaysOnTop, MainWindow.Settings.Advanced.IsAlwaysOnTop); } - - // UIA置顶 var toggleSwitchUIAccessTopMost = FindToggleSwitch("ToggleSwitchUIAccessTopMost"); if (toggleSwitchUIAccessTopMost != null && MainWindow.Settings.Advanced != null) { SetToggleSwitchState(toggleSwitchUIAccessTopMost, MainWindow.Settings.Advanced.EnableUIAccessTopMost); } - - // 更新通道 if (MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Release) { UpdateUpdateChannelButtons(true); @@ -188,8 +145,6 @@ namespace Ink_Canvas.Windows.SettingsViews { UpdateUpdateChannelButtons(false); } - - // 仅PPT模式 var toggleSwitchMode = FindToggleSwitch("ToggleSwitchMode"); if (toggleSwitchMode != null && MainWindow.Settings.ModeSettings != null) { @@ -198,37 +153,27 @@ namespace Ink_Canvas.Windows.SettingsViews } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine($"加载启动设置时出错: {ex.Message}"); + System.Diagnostics.Debug.WriteLine($"加载启动设置时出�? {ex.Message}"); } _isLoaded = true; } - - /// - /// 查找ToggleSwitch控件 - /// private Border FindToggleSwitch(string name) { return this.FindDescendantByName(name) as Border; } - - /// - /// 设置ToggleSwitch状态 - /// 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 + ? ThemeHelper.GetToggleSwitchOnBackgroundBrush() + : ThemeHelper.GetToggleSwitchOffBackgroundBrush(); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left; } } - - /// - /// ToggleSwitch点击事件处理 - /// private void ToggleSwitch_Click(object sender, RoutedEventArgs e) { if (!_isLoaded) return; @@ -236,7 +181,7 @@ namespace Ink_Canvas.Windows.SettingsViews var border = sender as Border; if (border == null) return; - bool isOn = border.Background.ToString() == "#FF3584E4"; + bool isOn = ThemeHelper.IsToggleSwitchOn(border.Background); bool newState = !isOn; SetToggleSwitchState(border, newState); @@ -246,9 +191,7 @@ namespace Ink_Canvas.Windows.SettingsViews switch (tag) { case "IsAutoUpdate": - // 直接调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsAutoUpdate", newState); - // 更新UI状态 var toggleSwitchIsAutoUpdateWithSilence = FindToggleSwitch("ToggleSwitchIsAutoUpdateWithSilence"); if (toggleSwitchIsAutoUpdateWithSilence != null) { @@ -263,45 +206,32 @@ namespace Ink_Canvas.Windows.SettingsViews break; case "IsAutoUpdateWithSilence": - // 直接调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsAutoUpdateWithSilence", newState); - // 更新UI状态 - if (AutoUpdateTimePeriodBlock != null) { AutoUpdateTimePeriodBlock.Visibility = newState ? Visibility.Visible : Visibility.Collapsed; } break; case "RunAtStartup": - // 直接调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchRunAtStartup", newState); break; case "FoldAtStartup": - // 直接调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchFoldAtStartup", newState); break; case "NoFocusMode": - // 窗口无焦点模式 - MainWindowSettingsHelper.UpdateSettingDirectly(() => + if (MainWindow.Settings.Advanced != null) { - if (MainWindow.Settings.Advanced != null) - { - MainWindow.Settings.Advanced.IsNoFocusMode = newState; - } - }, "ToggleSwitchNoFocusMode"); - // 调用 ApplyNoFocusMode 方法 + MainWindow.Settings.Advanced.IsNoFocusMode = newState; + } MainWindowSettingsHelper.InvokeMainWindowMethod("ApplyNoFocusMode"); break; case "WindowMode": - // 窗口无边框模式 - MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchWindowMode", newState); break; case "AlwaysOnTop": - // 窗口置顶 MainWindowSettingsHelper.UpdateSettingDirectly(() => { if (MainWindow.Settings.Advanced != null) @@ -309,12 +239,10 @@ namespace Ink_Canvas.Windows.SettingsViews MainWindow.Settings.Advanced.IsAlwaysOnTop = newState; } }, "ToggleSwitchAlwaysOnTop"); - // 调用 SetAlwaysOnTop 方法(如果存在) MainWindowSettingsHelper.InvokeMainWindowMethod("SetAlwaysOnTop", newState); break; case "UIAccessTopMost": - // UIA置顶 MainWindowSettingsHelper.UpdateSettingDirectly(() => { if (MainWindow.Settings.Advanced != null) @@ -325,15 +253,10 @@ namespace Ink_Canvas.Windows.SettingsViews break; case "Mode": - // 仅PPT模式 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchMode", newState); break; } } - - /// - /// 选项按钮点击事件处理 - /// private void OptionButton_Click(object sender, RoutedEventArgs e) { if (!_isLoaded) return; @@ -347,107 +270,80 @@ namespace Ink_Canvas.Windows.SettingsViews switch (tag) { case "UpdateChannel_Release": - // 选择稳定版 - MainWindowSettingsHelper.UpdateSettingDirectly(() => { MainWindow.Settings.Startup.UpdateChannel = UpdateChannel.Release; - }, "UpdateChannelSelector"); - // 调用 MainWindow 中的方法 - MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", - new System.Windows.Controls.RadioButton { Tag = "Release" }, e); - // 更新UI状态 - UpdateUpdateChannelButtons(true); + MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", + new System.Windows.Controls.RadioButton { Tag = "Release" }, e); + UpdateUpdateChannelButtons(true); + } break; case "UpdateChannel_Beta": - // 选择测试版 - MainWindowSettingsHelper.UpdateSettingDirectly(() => { MainWindow.Settings.Startup.UpdateChannel = UpdateChannel.Beta; - }, "UpdateChannelSelector"); - // 调用 MainWindow 中的方法 - MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", - new System.Windows.Controls.RadioButton { Tag = "Beta" }, e); - // 更新UI状态 - UpdateUpdateChannelButtons(false); + MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", + new System.Windows.Controls.RadioButton { Tag = "Beta" }, e); + UpdateUpdateChannelButtons(false); + } break; } } - - /// - /// 更新更新通道按钮状态 - /// private void UpdateUpdateChannelButtons(bool isReleaseSelected) { try { - // 使用 ThemeHelper 的统一方法设置按钮状态,与其他选项按钮保持一致 - ThemeHelper.SetOptionButtonSelectedState(UpdateChannelReleaseBorder, isReleaseSelected); - ThemeHelper.SetOptionButtonSelectedState(UpdateChannelBetaBorder, !isReleaseSelected); + if (UpdateChannelReleaseBorder != null) + { + ThemeHelper.SetOptionButtonSelectedState(UpdateChannelReleaseBorder, isReleaseSelected); + } + + if (UpdateChannelBetaBorder != null) + { + ThemeHelper.SetOptionButtonSelectedState(UpdateChannelBetaBorder, !isReleaseSelected); + } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"更新更新通道按钮状态时出错: {ex.Message}"); } } - - /// - /// 手动更新按钮点击事件 - /// private async void ManualUpdateButton_Click(object sender, RoutedEventArgs e) { MainWindowSettingsHelper.InvokeMainWindowMethod("ManualUpdateButton_Click", sender, e); } - - /// - /// 版本修复按钮点击事件 - /// private async void FixVersionButton_Click(object sender, RoutedEventArgs e) { MainWindowSettingsHelper.InvokeMainWindowMethod("FixVersionButton_Click", sender, e); } - - /// - /// 历史版本回滚按钮点击事件 - /// private void HistoryRollbackButton_Click(object sender, RoutedEventArgs e) { - // 查找 MainWindow 中的历史版本回滚方法 MainWindowSettingsHelper.InvokeMainWindowMethod("HistoryRollbackButton_Click", sender, e); } - - /// - /// ComboBox选择变化事件处理 - /// private void AutoUpdateWithSilenceStartTimeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!_isLoaded) return; - // 直接调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("AutoUpdateWithSilenceStartTimeComboBox", AutoUpdateWithSilenceStartTimeComboBox?.SelectedItem); } private void AutoUpdateWithSilenceEndTimeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!_isLoaded) return; - // 直接调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("AutoUpdateWithSilenceEndTimeComboBox", AutoUpdateWithSilenceEndTimeComboBox?.SelectedItem); } - - /// - /// 应用主题 - /// public void ApplyTheme() { try { - // 更新更新通道按钮 - 使用统一的方法保持与其他选项按钮一致 - if (MainWindow.Settings?.Startup != null) + bool isDarkTheme = ThemeHelper.IsDarkTheme; + // 更新更新通道按钮状态 + if (MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Release) { - bool isReleaseSelected = MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Release; - UpdateUpdateChannelButtons(isReleaseSelected); + UpdateUpdateChannelButtons(true); + } + else + { + UpdateUpdateChannelButtons(false); } - - // 更新按钮 if (ManualUpdateButton != null) { ManualUpdateButton.Background = ThemeHelper.GetButtonBackgroundBrush(); @@ -463,19 +359,29 @@ namespace Ink_Canvas.Windows.SettingsViews HistoryRollbackButton.Background = ThemeHelper.GetButtonBackgroundBrush(); HistoryRollbackButton.Foreground = ThemeHelper.GetTextPrimaryBrush(); } - - // 使用 ThemeHelper 递归更新其他元素 ThemeHelper.ApplyThemeToControl(this); - - if (MainWindow.Settings?.Startup != null) - { - bool isReleaseSelected = MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Release; - UpdateUpdateChannelButtons(isReleaseSelected); - } + UpdateComboBoxDropdownTheme(AutoUpdateWithSilenceStartTimeComboBox); + UpdateComboBoxDropdownTheme(AutoUpdateWithSilenceEndTimeComboBox); } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine($"StartupPanel 应用主题时出错: {ex.Message}"); + System.Diagnostics.Debug.WriteLine($"StartupPanel 应用主题时出�? {ex.Message}"); + } + } + private void UpdateComboBoxDropdownTheme(System.Windows.Controls.ComboBox comboBox) + { + if (comboBox == null) return; + comboBox.DropDownOpened -= ComboBox_DropDownOpened; + comboBox.DropDownOpened += ComboBox_DropDownOpened; + } + private void ComboBox_DropDownOpened(object sender, EventArgs e) + { + if (sender is System.Windows.Controls.ComboBox comboBox) + { + Dispatcher.BeginInvoke(new Action(() => + { + ThemeHelper.UpdateComboBoxDropdownColors(comboBox); + }), System.Windows.Threading.DispatcherPriority.Loaded); } } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs index c7db8819..8e89484b 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -48,7 +48,7 @@ namespace Ink_Canvas.Windows.SettingsViews public static Color ButtonHoverBackground => IsDarkTheme ? Color.FromRgb(55, 55, 55) : Color.FromRgb(210, 210, 210); public static Color ToggleSwitchOnBackground => IsDarkTheme ? Color.FromRgb(0, 122, 204) : Color.FromRgb(53, 132, 228); public static Color ToggleSwitchOffBackground => IsDarkTheme ? ButtonBackground : Color.FromRgb(225, 225, 225); - public static Color OptionButtonSelectedBackground => SelectedBackground; + public static Color OptionButtonSelectedBackground => IsDarkTheme ? Color.FromRgb(62, 62, 62) : Color.FromRgb(235, 235, 235); public static Color OptionButtonUnselectedBackground => Colors.Transparent; public static Color OptionButtonSelectedBorder => IsDarkTheme ? Color.FromRgb(100, 100, 100) : Color.FromRgb(160, 160, 160); public static Color OptionButtonUnselectedBorder => IsDarkTheme ? Color.FromRgb(50, 50, 50) : Color.FromRgb(220, 220, 220); diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs index 55b071f4..26010129 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs @@ -1,4 +1,4 @@ -using Ink_Canvas; +using Ink_Canvas; using iNKORE.UI.WPF.Helpers; using System; using System.Collections.Generic; @@ -11,9 +11,6 @@ using Hardcodet.Wpf.TaskbarNotification; namespace Ink_Canvas.Windows.SettingsViews { - /// - /// ThemePanel.xaml 的交互逻辑 - /// public partial class ThemePanel : UserControl { private bool _isLoaded = false; @@ -27,21 +24,15 @@ namespace Ink_Canvas.Windows.SettingsViews private void ThemePanel_Loaded(object sender, RoutedEventArgs e) { LoadSettings(); - // 添加触摸支持 EnableTouchSupport(); - // 应用主题 ApplyTheme(); _isLoaded = true; } - /// - /// 为面板中的所有交互控件启用触摸支持 - /// private void EnableTouchSupport() { try { - // 延迟执行,确保所有控件都已加载 Dispatcher.BeginInvoke(new Action(() => { MainWindowSettingsHelper.EnableTouchSupportForControls(this); @@ -49,7 +40,7 @@ namespace Ink_Canvas.Windows.SettingsViews } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine($"ThemePanel 启用触摸支持时出错: {ex.Message}"); + System.Diagnostics.Debug.WriteLine($"ThemePanel 启用触摸支持时出�? {ex.Message}"); } } @@ -70,9 +61,6 @@ namespace Ink_Canvas.Windows.SettingsViews } } - /// - /// 加载设置到UI - /// public void LoadSettings() { if (MainWindow.Settings == null || MainWindow.Settings.Appearance == null) return; @@ -83,33 +71,25 @@ namespace Ink_Canvas.Windows.SettingsViews { var appearance = MainWindow.Settings.Appearance; - // 主题设置 SetOptionButtonState("Theme", appearance.Theme); - // 启用启动动画 SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableSplashScreen"), appearance.EnableSplashScreen); if (SplashScreenStylePanel != null) { SplashScreenStylePanel.Visibility = appearance.EnableSplashScreen ? Visibility.Visible : Visibility.Collapsed; } - // 启动动画样式 if (ComboBoxSplashScreenStyle != null) { ComboBoxSplashScreenStyle.SelectedIndex = Math.Min(appearance.SplashScreenStyle, ComboBoxSplashScreenStyle.Items.Count - 1); } - // 浮动工具栏图标 if (ComboBoxFloatingBarImg != null) { - // 更新自定义图标列表(如果需要) - // UpdateCustomIconsInComboBox(); - int selectedIndex = Math.Min(appearance.FloatingBarImg, ComboBoxFloatingBarImg.Items.Count - 1); ComboBoxFloatingBarImg.SelectedIndex = selectedIndex; } - // 浮动工具栏缩放 if (ViewboxFloatingBarScaleTransformValueSlider != null) { double val = appearance.ViewboxFloatingBarScaleTransformValue; @@ -121,7 +101,6 @@ namespace Ink_Canvas.Windows.SettingsViews } } - // 浮动工具栏透明度 if (ViewboxFloatingBarOpacityValueSlider != null) { ViewboxFloatingBarOpacityValueSlider.Value = appearance.ViewboxFloatingBarOpacityValue; @@ -131,7 +110,6 @@ namespace Ink_Canvas.Windows.SettingsViews } } - // 浮栏在PPT下透明度 if (ViewboxFloatingBarOpacityInPPTValueSlider != null) { ViewboxFloatingBarOpacityInPPTValueSlider.Value = appearance.ViewboxFloatingBarOpacityInPPTValue; @@ -141,16 +119,13 @@ namespace Ink_Canvas.Windows.SettingsViews } } - // 在调色盘窗口中显示笔尖模式按钮 SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableDisPlayNibModeToggle"), appearance.IsEnableDisPlayNibModeToggler); - // 使用老版浮动栏按钮UI if (CheckBoxUseLegacyFloatingBarUI != null) { CheckBoxUseLegacyFloatingBarUI.IsChecked = appearance.UseLegacyFloatingBarUI; } - // 浮动栏按钮显示控制 if (CheckBoxShowShapeButton != null) CheckBoxShowShapeButton.IsChecked = appearance.IsShowShapeButton; if (CheckBoxShowUndoButton != null) CheckBoxShowUndoButton.IsChecked = appearance.IsShowUndoButton; if (CheckBoxShowRedoButton != null) CheckBoxShowRedoButton.IsChecked = appearance.IsShowRedoButton; @@ -161,76 +136,58 @@ namespace Ink_Canvas.Windows.SettingsViews if (CheckBoxShowLassoSelectButton != null) CheckBoxShowLassoSelectButton.IsChecked = appearance.IsShowLassoSelectButton; if (CheckBoxShowClearAndMouseButton != null) CheckBoxShowClearAndMouseButton.IsChecked = appearance.IsShowClearAndMouseButton; - // 启用系统托盘图标 SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableTrayIcon"), appearance.EnableTrayIcon); - // 画板UI缩放 SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableViewboxBlackBoardScaleTransform"), appearance.EnableViewboxBlackBoardScaleTransform); - // 白板模式时间显示 SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableTimeDisplayInWhiteboardMode"), appearance.EnableTimeDisplayInWhiteboardMode); - // 白板模式鸡汤文 SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableChickenSoupInWhiteboardMode"), appearance.EnableChickenSoupInWhiteboardMode); - // 启用快捷面板 SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableQuickPanel"), appearance.IsShowQuickPanel); - // 退出折叠模式后自动进入批注模式 if (MainWindow.Settings.Automation != null) { SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoEnterAnnotationModeWhenExitFoldMode"), MainWindow.Settings.Automation.IsAutoEnterAnnotationModeWhenExitFoldMode); } - // PPT放映结束后自动折叠 if (MainWindow.Settings.Automation != null) { SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoFoldAfterPPTSlideShow"), MainWindow.Settings.Automation.IsAutoFoldAfterPPTSlideShow); } - // 退出白板模式后自动折叠 if (MainWindow.Settings.Automation != null) { SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoFoldWhenExitWhiteboard"), MainWindow.Settings.Automation.IsAutoFoldWhenExitWhiteboard); } - // 信仰の源出自Where? SetOptionButtonState("ChickenSoupSource", appearance.ChickenSoupSource); - // 取消收纳按钮图标 SetOptionButtonState("UnFoldBtnImg", appearance.UnFoldButtonImageType); - // 快捷调色盘显示模式 SetOptionButtonState("QuickColorPaletteDisplayMode", appearance.QuickColorPaletteDisplayMode); - // 橡皮按钮显示 SetOptionButtonState("EraserDisplayOption", appearance.EraserDisplayOption); } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine($"加载个性化设置时出错: {ex.Message}"); + System.Diagnostics.Debug.WriteLine($"加载个性化设置时出�? {ex.Message}"); } _isLoaded = true; } - /// - /// 查找ToggleSwitch控件 - /// private Border FindToggleSwitch(string name) { return this.FindDescendantByName(name) as Border; } - /// - /// 设置ToggleSwitch状态 - /// 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)); + ? ThemeHelper.GetToggleSwitchOnBackgroundBrush() + : ThemeHelper.GetToggleSwitchOffBackgroundBrush(); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { @@ -238,9 +195,6 @@ namespace Ink_Canvas.Windows.SettingsViews } } - /// - /// ToggleSwitch点击事件处理 - /// private void ToggleSwitch_Click(object sender, RoutedEventArgs e) { if (!_isLoaded) return; @@ -248,7 +202,7 @@ namespace Ink_Canvas.Windows.SettingsViews var border = sender as Border; if (border == null) return; - bool isOn = border.Background.ToString() == "#FF3584E4"; + bool isOn = ThemeHelper.IsToggleSwitchOn(border.Background); bool newState = !isOn; SetToggleSwitchState(border, newState); @@ -261,9 +215,7 @@ namespace Ink_Canvas.Windows.SettingsViews switch (tag) { case "EnableSplashScreen": - // 调用 MainWindow 中的方法(带主题检查) MainWindowSettingsHelper.InvokeToggleSwitchToggledWithThemeCheck("ToggleSwitchEnableSplashScreen", newState); - // 更新UI状态 if (SplashScreenStylePanel != null) { SplashScreenStylePanel.Visibility = newState ? Visibility.Visible : Visibility.Collapsed; @@ -271,14 +223,11 @@ namespace Ink_Canvas.Windows.SettingsViews break; case "EnableDisPlayNibModeToggle": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableDisPlayNibModeToggle", newState); break; case "EnableTrayIcon": - // 调用 MainWindow 中的方法(带主题检查) MainWindowSettingsHelper.InvokeToggleSwitchToggledWithThemeCheck("ToggleSwitchEnableTrayIcon", newState); - // 更新系统托盘图标可见性 var taskbar = Application.Current.Resources["TaskbarTrayIcon"] as TaskbarIcon; if (taskbar != null) { @@ -287,51 +236,40 @@ namespace Ink_Canvas.Windows.SettingsViews break; case "EnableViewboxBlackBoardScaleTransform": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableViewboxBlackBoardScaleTransform", newState); break; case "EnableTimeDisplayInWhiteboardMode": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableTimeDisplayInWhiteboardMode", newState); break; case "EnableChickenSoupInWhiteboardMode": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableChickenSoupInWhiteboardMode", newState); break; case "EnableQuickPanel": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableQuickPanel", newState); break; case "AutoEnterAnnotationModeWhenExitFoldMode": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoEnterAnnotationModeWhenExitFoldMode", newState); break; case "AutoFoldAfterPPTSlideShow": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoFoldAfterPPTSlideShow", newState); break; case "AutoFoldWhenExitWhiteboard": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoFoldWhenExitWhiteboard", newState); break; } } - /// - /// ComboBox选择变化事件处理 - /// private void ComboBoxSplashScreenStyle_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!_isLoaded) return; if (ComboBoxSplashScreenStyle?.SelectedIndex >= 0) { - // 调用 MainWindow 中的方法(带主题检查) MainWindowSettingsHelper.InvokeComboBoxSelectionChangedWithThemeCheck("ComboBoxSplashScreenStyle", ComboBoxSplashScreenStyle.SelectedItem); } } @@ -341,14 +279,10 @@ namespace Ink_Canvas.Windows.SettingsViews if (!_isLoaded) return; if (ComboBoxFloatingBarImg?.SelectedIndex >= 0) { - // 调用 MainWindow 中的方法(带主题检查) MainWindowSettingsHelper.InvokeComboBoxSelectionChangedWithThemeCheck("ComboBoxFloatingBarImg", ComboBoxFloatingBarImg.SelectedItem); } } - /// - /// Slider值变化事件处理 - /// private void ViewboxFloatingBarScaleTransformValueSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { if (!_isLoaded) return; @@ -356,7 +290,6 @@ namespace Ink_Canvas.Windows.SettingsViews { double val = ViewboxFloatingBarScaleTransformValueSlider.Value; ViewboxFloatingBarScaleTransformValueText.Text = val.ToString("F2"); - // 调用 MainWindow 中的方法(会自动检查主题更新) MainWindowSettingsHelper.InvokeSliderValueChanged("ViewboxFloatingBarScaleTransformValueSlider", val); } } @@ -368,7 +301,6 @@ namespace Ink_Canvas.Windows.SettingsViews { double val = ViewboxFloatingBarOpacityValueSlider.Value; ViewboxFloatingBarOpacityValueText.Text = val.ToString("F2"); - // 调用 MainWindow 中的方法(会自动检查主题更新) MainWindowSettingsHelper.InvokeSliderValueChanged("ViewboxFloatingBarOpacityValueSlider", val); } } @@ -380,14 +312,10 @@ namespace Ink_Canvas.Windows.SettingsViews { double val = ViewboxFloatingBarOpacityInPPTValueSlider.Value; ViewboxFloatingBarOpacityInPPTValueText.Text = val.ToString("F2"); - // 调用 MainWindow 中的方法(会自动检查主题更新) MainWindowSettingsHelper.InvokeSliderValueChanged("ViewboxFloatingBarOpacityInPPTValueSlider", val); } } - /// - /// CheckBox变化事件处理 - /// private void CheckBox_CheckedChanged(object sender, RoutedEventArgs e) { if (!_isLoaded) return; @@ -402,60 +330,47 @@ namespace Ink_Canvas.Windows.SettingsViews switch (name) { case "CheckBoxUseLegacyFloatingBarUI": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged("CheckBoxUseLegacyFloatingBarUI", checkBox.IsChecked ?? false); break; case "CheckBoxShowShapeButton": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged("CheckBoxShowShapeButton", checkBox.IsChecked ?? false); break; case "CheckBoxShowUndoButton": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged("CheckBoxShowUndoButton", checkBox.IsChecked ?? false); break; case "CheckBoxShowRedoButton": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged("CheckBoxShowRedoButton", checkBox.IsChecked ?? false); break; case "CheckBoxShowClearButton": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged("CheckBoxShowClearButton", checkBox.IsChecked ?? false); break; case "CheckBoxShowWhiteboardButton": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged("CheckBoxShowWhiteboardButton", checkBox.IsChecked ?? false); break; case "CheckBoxShowHideButton": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged("CheckBoxShowHideButton", checkBox.IsChecked ?? false); break; case "CheckBoxShowQuickColorPalette": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged("CheckBoxShowQuickColorPalette", checkBox.IsChecked ?? false); break; case "CheckBoxShowLassoSelectButton": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged("CheckBoxShowLassoSelectButton", checkBox.IsChecked ?? false); break; case "CheckBoxShowClearAndMouseButton": - // 调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged("CheckBoxShowClearAndMouseButton", checkBox.IsChecked ?? false); break; } } - /// - /// 设置选项按钮状态 - /// private void SetOptionButtonState(string group, int selectedIndex) { var buttons = new Dictionary @@ -476,31 +391,11 @@ namespace Ink_Canvas.Windows.SettingsViews var button = this.FindDescendantByName($"{group}{buttonNames[i]}Border") as Border; if (button != null) { - if (i == selectedIndex) - { - button.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225)); - var textBlock = button.Child as TextBlock; - if (textBlock != null) - { - textBlock.FontWeight = FontWeights.Bold; - } - } - else - { - button.Background = new SolidColorBrush(Colors.Transparent); - var textBlock = button.Child as TextBlock; - if (textBlock != null) - { - textBlock.FontWeight = FontWeights.Normal; - } - } + ThemeHelper.SetOptionButtonSelectedState(button, i == selectedIndex); } } } - /// - /// 选项按钮点击事件处理 - /// private void OptionButton_Click(object sender, RoutedEventArgs e) { if (!_isLoaded) return; @@ -517,7 +412,6 @@ namespace Ink_Canvas.Windows.SettingsViews string group = parts[0]; string value = parts[1]; - // 清除同组其他按钮的选中状态 var parent = border.Parent as Panel; if (parent != null) { @@ -528,24 +422,13 @@ namespace Ink_Canvas.Windows.SettingsViews string childTag = childBorder.Tag?.ToString(); if (!string.IsNullOrEmpty(childTag) && childTag.StartsWith(group + "_")) { - childBorder.Background = new SolidColorBrush(Colors.Transparent); - var textBlock = childBorder.Child as TextBlock; - if (textBlock != null) - { - textBlock.FontWeight = FontWeights.Normal; - } + ThemeHelper.SetOptionButtonSelectedState(childBorder, false); } } } } - // 设置当前按钮为选中状态 - border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225)); - var currentTextBlock = border.Child as TextBlock; - if (currentTextBlock != null) - { - currentTextBlock.FontWeight = FontWeights.Bold; - } + ThemeHelper.SetOptionButtonSelectedState(border, true); var appearance = MainWindow.Settings.Appearance; if (appearance == null) return; @@ -553,7 +436,6 @@ namespace Ink_Canvas.Windows.SettingsViews switch (group) { case "Theme": - // 通过 MainWindowSettingsHelper 调用 ComboBoxTheme 的 SelectionChanged 事件处理器 try { var mainWindow = Application.Current.MainWindow as MainWindow; @@ -562,23 +444,22 @@ namespace Ink_Canvas.Windows.SettingsViews var comboBox = mainWindow.FindName("ComboBoxTheme") as System.Windows.Controls.ComboBox; if (comboBox != null) { - // 根据 value 找到对应的 ComboBoxItem - int themeIndex; - switch (value) - { - case "Light": - themeIndex = 0; - break; - case "Dark": - themeIndex = 1; - break; - case "System": - themeIndex = 2; - break; - default: - themeIndex = 2; - break; - } + int themeIndex; + switch (value) + { + case "Light": + themeIndex = 0; + break; + case "Dark": + themeIndex = 1; + break; + case "System": + themeIndex = 2; + break; + default: + themeIndex = 2; + break; + } if (comboBox.Items.Count > themeIndex) { @@ -586,21 +467,18 @@ namespace Ink_Canvas.Windows.SettingsViews MainWindowSettingsHelper.InvokeComboBoxSelectionChangedWithThemeCheck("ComboBoxTheme", selectedItem); } else - { - // 如果找不到控件,直接更新设置并通知主题更新 + { MainWindowSettingsHelper.UpdateSettingSafely(() => { appearance.Theme = themeIndex; }, "ComboBoxTheme_SelectionChanged", "ComboBoxTheme"); MainWindowSettingsHelper.NotifyThemeUpdateIfNeeded("ComboBoxTheme"); - // 触发主题变化事件,通知设置窗口更新主题 ThemeChanged?.Invoke(this, new RoutedEventArgs()); } } else { - // 如果找不到控件,直接更新设置并通知主题更新 int themeIndex; switch (value) { @@ -622,15 +500,14 @@ namespace Ink_Canvas.Windows.SettingsViews appearance.Theme = themeIndex; }, "ComboBoxTheme_SelectionChanged", "ComboBoxTheme"); MainWindowSettingsHelper.NotifyThemeUpdateIfNeeded("ComboBoxTheme"); - - // 触发主题变化事件,通知设置窗口更新主题 - ThemeChanged?.Invoke(this, new RoutedEventArgs()); + + ThemeChanged?.Invoke(this, new RoutedEventArgs()); } } } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine($"切换主题时出错: {ex.Message}"); + System.Diagnostics.Debug.WriteLine($"切换主题时出�? {ex.Message}"); } break; @@ -654,7 +531,6 @@ namespace Ink_Canvas.Windows.SettingsViews sourceIndex = 3; break; } - // 调用 MainWindow 中的方法 var mainWindow6 = Application.Current.MainWindow as MainWindow; if (mainWindow6 != null) { @@ -666,10 +542,9 @@ namespace Ink_Canvas.Windows.SettingsViews } else { - // 如果找不到控件,直接更新设置 MainWindowSettingsHelper.UpdateSettingDirectly(() => { - appearance.ChickenSoupSource = sourceIndex; + appearance.ChickenSoupSource = sourceIndex; }, "ComboBoxChickenSoupSource"); } } @@ -689,7 +564,6 @@ namespace Ink_Canvas.Windows.SettingsViews imgType = 0; break; } - // 调用 MainWindow 中的方法(带主题检查) var mainWindow3 = Application.Current.MainWindow as MainWindow; if (mainWindow3 != null) { @@ -701,10 +575,9 @@ namespace Ink_Canvas.Windows.SettingsViews } else { - // 如果找不到控件,直接更新设置并通知主题更新 MainWindowSettingsHelper.UpdateSettingSafely(() => { - appearance.UnFoldButtonImageType = imgType; + appearance.UnFoldButtonImageType = imgType; }, "ComboBoxUnFoldBtnImg_SelectionChanged", "ComboBoxUnFoldBtnImg"); MainWindowSettingsHelper.NotifyThemeUpdateIfNeeded("ComboBoxUnFoldBtnImg"); } @@ -725,7 +598,6 @@ namespace Ink_Canvas.Windows.SettingsViews displayMode = 1; break; } - // 调用 MainWindow 中的方法 var mainWindow4 = Application.Current.MainWindow as MainWindow; if (mainWindow4 != null) { @@ -737,10 +609,9 @@ namespace Ink_Canvas.Windows.SettingsViews } else { - // 如果找不到控件,直接更新设置 MainWindowSettingsHelper.UpdateSettingDirectly(() => { - appearance.QuickColorPaletteDisplayMode = displayMode; + appearance.QuickColorPaletteDisplayMode = displayMode; }, "ComboBoxQuickColorPaletteDisplayMode"); } } @@ -766,7 +637,6 @@ namespace Ink_Canvas.Windows.SettingsViews eraserOption = 0; break; } - // 调用 MainWindow 中的方法 var mainWindow5 = Application.Current.MainWindow as MainWindow; if (mainWindow5 != null) { @@ -778,10 +648,9 @@ namespace Ink_Canvas.Windows.SettingsViews } else { - // 如果找不到控件,直接更新设置 MainWindowSettingsHelper.UpdateSettingDirectly(() => { - appearance.EraserDisplayOption = eraserOption; + appearance.EraserDisplayOption = eraserOption; }, "ComboBoxEraserDisplayOption"); } } @@ -789,18 +658,46 @@ namespace Ink_Canvas.Windows.SettingsViews } } - /// - /// 应用主题 - /// public void ApplyTheme() { try { ThemeHelper.ApplyThemeToControl(this); + if (MainWindow.Settings?.Appearance != null) + { + var appearance = MainWindow.Settings.Appearance; + SetOptionButtonState("Theme", appearance.Theme); + SetOptionButtonState("ChickenSoupSource", appearance.ChickenSoupSource); + SetOptionButtonState("UnFoldBtnImg", appearance.UnFoldButtonImageType); + SetOptionButtonState("QuickColorPaletteDisplayMode", appearance.QuickColorPaletteDisplayMode); + SetOptionButtonState("EraserDisplayOption", appearance.EraserDisplayOption); + } + + UpdateComboBoxDropdownTheme(ComboBoxSplashScreenStyle); + UpdateComboBoxDropdownTheme(ComboBoxFloatingBarImg); } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine($"ThemePanel 应用主题时出错: {ex.Message}"); + System.Diagnostics.Debug.WriteLine($"ThemePanel 应用主题时出�? {ex.Message}"); + } + } + + private void UpdateComboBoxDropdownTheme(System.Windows.Controls.ComboBox comboBox) + { + if (comboBox == null) return; + + comboBox.DropDownOpened -= ComboBox_DropDownOpened; + comboBox.DropDownOpened += ComboBox_DropDownOpened; + } + + private void ComboBox_DropDownOpened(object sender, EventArgs e) + { + if (sender is System.Windows.Controls.ComboBox comboBox) + { + Dispatcher.BeginInvoke(new Action(() => + { + ThemeHelper.UpdateComboBoxDropdownColors(comboBox); + }), System.Windows.Threading.DispatcherPriority.Loaded); } } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/TimerPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/TimerPanel.xaml.cs index 71f4322b..f0681123 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/TimerPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/TimerPanel.xaml.cs @@ -92,7 +92,7 @@ namespace Ink_Canvas.Windows.SettingsViews } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine($"TimerPanel 应用主题时出错: {ex.Message}"); + System.Diagnostics.Debug.WriteLine($"TimerPanel 应用主题时出�? {ex.Message}"); } } private void TimerVolumeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)