From acafdcc991fe6db487293a6717e7fb5a8b0d3131 Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Fri, 2 Jan 2026 13:38:04 +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 | 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, 354 insertions(+), 127 deletions(-) diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs index e85bd430..3354a26e 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs @@ -483,12 +483,18 @@ namespace Ink_Canvas.Windows.SettingsViews if (isRegistered) { FileAssociationStatusText.Text = "✓ .icstk文件关联已注册"; - FileAssociationStatusText.Foreground = new SolidColorBrush(Colors.LightGreen); + // 使用主题适配的绿色 + FileAssociationStatusText.Foreground = ThemeHelper.IsDarkTheme + ? new SolidColorBrush(Color.FromRgb(76, 175, 80)) // 深色主题下的绿色 + : new SolidColorBrush(Color.FromRgb(46, 125, 50)); // 浅色主题下的绿色 } else { FileAssociationStatusText.Text = "✗ .icstk文件关联未注册"; - FileAssociationStatusText.Foreground = new SolidColorBrush(Colors.LightCoral); + // 使用主题适配的红色 + FileAssociationStatusText.Foreground = ThemeHelper.IsDarkTheme + ? new SolidColorBrush(Color.FromRgb(244, 67, 54)) // 深色主题下的红色 + : new SolidColorBrush(Color.FromRgb(198, 40, 40)); // 浅色主题下的红色 } } } @@ -498,7 +504,10 @@ namespace Ink_Canvas.Windows.SettingsViews { FileAssociationStatusText.Visibility = Visibility.Visible; FileAssociationStatusText.Text = $"✗ 检查文件关联状态时出错: {ex.Message}"; - FileAssociationStatusText.Foreground = new SolidColorBrush(Colors.LightCoral); + // 使用主题适配的红色 + FileAssociationStatusText.Foreground = ThemeHelper.IsDarkTheme + ? new SolidColorBrush(Color.FromRgb(244, 67, 54)) // 深色主题下的红色 + : new SolidColorBrush(Color.FromRgb(198, 40, 40)); // 浅色主题下的红色 } } } @@ -512,6 +521,26 @@ 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 84ee798a..cbbeb49f 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs @@ -4,6 +4,7 @@ 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; @@ -413,7 +414,7 @@ namespace Ink_Canvas.Windows.SettingsViews } } - private void AutoSaveIntervalButton_Click(object sender, RoutedEventArgs e) + private void AutoSaveIntervalButton_Click(object sender, MouseButtonEventArgs e) { if (!_isLoaded) return; diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml index b03a97b4..dd7c5721 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 4b90263d..0403c705 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,6 +8,9 @@ using System.Windows.Media; namespace Ink_Canvas.Windows.SettingsViews { + /// + /// StartupPanel.xaml 的交互逻辑 + /// public partial class StartupPanel : UserControl { private bool _isLoaded = false; @@ -21,14 +24,21 @@ 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); @@ -36,11 +46,16 @@ 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); } @@ -59,6 +74,10 @@ namespace Ink_Canvas.Windows.SettingsViews IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs()); } } + + /// + /// 加载设置到UI + /// public void LoadSettings() { if (MainWindow.Settings == null) return; @@ -67,12 +86,15 @@ 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) { @@ -80,11 +102,17 @@ 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() @@ -105,38 +133,53 @@ 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); @@ -145,6 +188,8 @@ namespace Ink_Canvas.Windows.SettingsViews { UpdateUpdateChannelButtons(false); } + + // 仅PPT模式 var toggleSwitchMode = FindToggleSwitch("ToggleSwitchMode"); if (toggleSwitchMode != null && MainWindow.Settings.ModeSettings != null) { @@ -153,27 +198,37 @@ 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 - ? ThemeHelper.GetToggleSwitchOnBackgroundBrush() - : ThemeHelper.GetToggleSwitchOffBackgroundBrush(); + toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) : new SolidColorBrush(Color.FromRgb(225, 225, 225)); 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; @@ -181,7 +236,7 @@ namespace Ink_Canvas.Windows.SettingsViews var border = sender as Border; if (border == null) return; - bool isOn = ThemeHelper.IsToggleSwitchOn(border.Background); + bool isOn = border.Background.ToString() == "#FF3584E4"; bool newState = !isOn; SetToggleSwitchState(border, newState); @@ -191,7 +246,9 @@ namespace Ink_Canvas.Windows.SettingsViews switch (tag) { case "IsAutoUpdate": + // 直接调用 MainWindow 中的方法 MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsAutoUpdate", newState); + // 更新UI状态 var toggleSwitchIsAutoUpdateWithSilence = FindToggleSwitch("ToggleSwitchIsAutoUpdateWithSilence"); if (toggleSwitchIsAutoUpdateWithSilence != null) { @@ -206,32 +263,45 @@ 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": - if (MainWindow.Settings.Advanced != null) + // 窗口无焦点模式 + MainWindowSettingsHelper.UpdateSettingDirectly(() => { - MainWindow.Settings.Advanced.IsNoFocusMode = newState; - } + if (MainWindow.Settings.Advanced != null) + { + MainWindow.Settings.Advanced.IsNoFocusMode = newState; + } + }, "ToggleSwitchNoFocusMode"); + // 调用 ApplyNoFocusMode 方法 MainWindowSettingsHelper.InvokeMainWindowMethod("ApplyNoFocusMode"); break; case "WindowMode": + // 窗口无边框模式 + MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchWindowMode", newState); break; case "AlwaysOnTop": + // 窗口置顶 MainWindowSettingsHelper.UpdateSettingDirectly(() => { if (MainWindow.Settings.Advanced != null) @@ -239,10 +309,12 @@ 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) @@ -253,10 +325,15 @@ 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; @@ -270,80 +347,107 @@ namespace Ink_Canvas.Windows.SettingsViews switch (tag) { case "UpdateChannel_Release": + // 选择稳定版 + MainWindowSettingsHelper.UpdateSettingDirectly(() => { MainWindow.Settings.Startup.UpdateChannel = UpdateChannel.Release; - MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", - new System.Windows.Controls.RadioButton { Tag = "Release" }, e); - UpdateUpdateChannelButtons(true); - } + }, "UpdateChannelSelector"); + // 调用 MainWindow 中的方法 + MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", + new System.Windows.Controls.RadioButton { Tag = "Release" }, e); + // 更新UI状态 + UpdateUpdateChannelButtons(true); break; case "UpdateChannel_Beta": + // 选择测试版 + MainWindowSettingsHelper.UpdateSettingDirectly(() => { MainWindow.Settings.Startup.UpdateChannel = UpdateChannel.Beta; - MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", - new System.Windows.Controls.RadioButton { Tag = "Beta" }, e); - UpdateUpdateChannelButtons(false); - } + }, "UpdateChannelSelector"); + // 调用 MainWindow 中的方法 + MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", + new System.Windows.Controls.RadioButton { Tag = "Beta" }, e); + // 更新UI状态 + UpdateUpdateChannelButtons(false); break; } } + + /// + /// 更新更新通道按钮状态 + /// private void UpdateUpdateChannelButtons(bool isReleaseSelected) { try { - if (UpdateChannelReleaseBorder != null) - { - ThemeHelper.SetOptionButtonSelectedState(UpdateChannelReleaseBorder, isReleaseSelected); - } - - if (UpdateChannelBetaBorder != null) - { - ThemeHelper.SetOptionButtonSelectedState(UpdateChannelBetaBorder, !isReleaseSelected); - } + // 使用 ThemeHelper 的统一方法设置按钮状态,与其他选项按钮保持一致 + ThemeHelper.SetOptionButtonSelectedState(UpdateChannelReleaseBorder, isReleaseSelected); + 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 { - bool isDarkTheme = ThemeHelper.IsDarkTheme; - // 更新更新通道按钮状态 - if (MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Release) + // 更新更新通道按钮 - 使用统一的方法保持与其他选项按钮一致 + if (MainWindow.Settings?.Startup != null) { - UpdateUpdateChannelButtons(true); - } - else - { - UpdateUpdateChannelButtons(false); + bool isReleaseSelected = MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Release; + UpdateUpdateChannelButtons(isReleaseSelected); } + + // 更新按钮 if (ManualUpdateButton != null) { ManualUpdateButton.Background = ThemeHelper.GetButtonBackgroundBrush(); @@ -359,29 +463,19 @@ namespace Ink_Canvas.Windows.SettingsViews HistoryRollbackButton.Background = ThemeHelper.GetButtonBackgroundBrush(); HistoryRollbackButton.Foreground = ThemeHelper.GetTextPrimaryBrush(); } + + // 使用 ThemeHelper 递归更新其他元素 ThemeHelper.ApplyThemeToControl(this); - UpdateComboBoxDropdownTheme(AutoUpdateWithSilenceStartTimeComboBox); - UpdateComboBoxDropdownTheme(AutoUpdateWithSilenceEndTimeComboBox); + + if (MainWindow.Settings?.Startup != null) + { + bool isReleaseSelected = MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Release; + UpdateUpdateChannelButtons(isReleaseSelected); + } } catch (Exception ex) { - 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); + System.Diagnostics.Debug.WriteLine($"StartupPanel 应用主题时出错: {ex.Message}"); } } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs index 8e89484b..c7db8819 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 => IsDarkTheme ? Color.FromRgb(62, 62, 62) : Color.FromRgb(235, 235, 235); + public static Color OptionButtonSelectedBackground => SelectedBackground; 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 26010129..55b071f4 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,6 +11,9 @@ using Hardcodet.Wpf.TaskbarNotification; namespace Ink_Canvas.Windows.SettingsViews { + /// + /// ThemePanel.xaml 的交互逻辑 + /// public partial class ThemePanel : UserControl { private bool _isLoaded = false; @@ -24,15 +27,21 @@ 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); @@ -40,7 +49,7 @@ namespace Ink_Canvas.Windows.SettingsViews } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine($"ThemePanel 启用触摸支持时出�? {ex.Message}"); + System.Diagnostics.Debug.WriteLine($"ThemePanel 启用触摸支持时出错: {ex.Message}"); } } @@ -61,6 +70,9 @@ namespace Ink_Canvas.Windows.SettingsViews } } + /// + /// 加载设置到UI + /// public void LoadSettings() { if (MainWindow.Settings == null || MainWindow.Settings.Appearance == null) return; @@ -71,25 +83,33 @@ 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; @@ -101,6 +121,7 @@ namespace Ink_Canvas.Windows.SettingsViews } } + // 浮动工具栏透明度 if (ViewboxFloatingBarOpacityValueSlider != null) { ViewboxFloatingBarOpacityValueSlider.Value = appearance.ViewboxFloatingBarOpacityValue; @@ -110,6 +131,7 @@ namespace Ink_Canvas.Windows.SettingsViews } } + // 浮栏在PPT下透明度 if (ViewboxFloatingBarOpacityInPPTValueSlider != null) { ViewboxFloatingBarOpacityInPPTValueSlider.Value = appearance.ViewboxFloatingBarOpacityInPPTValue; @@ -119,13 +141,16 @@ 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; @@ -136,58 +161,76 @@ 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 - ? ThemeHelper.GetToggleSwitchOnBackgroundBrush() - : ThemeHelper.GetToggleSwitchOffBackgroundBrush(); + ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) + : new SolidColorBrush(Color.FromRgb(225, 225, 225)); var innerBorder = toggleSwitch.Child as Border; if (innerBorder != null) { @@ -195,6 +238,9 @@ namespace Ink_Canvas.Windows.SettingsViews } } + /// + /// ToggleSwitch点击事件处理 + /// private void ToggleSwitch_Click(object sender, RoutedEventArgs e) { if (!_isLoaded) return; @@ -202,7 +248,7 @@ namespace Ink_Canvas.Windows.SettingsViews var border = sender as Border; if (border == null) return; - bool isOn = ThemeHelper.IsToggleSwitchOn(border.Background); + bool isOn = border.Background.ToString() == "#FF3584E4"; bool newState = !isOn; SetToggleSwitchState(border, newState); @@ -215,7 +261,9 @@ 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; @@ -223,11 +271,14 @@ 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) { @@ -236,40 +287,51 @@ 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); } } @@ -279,10 +341,14 @@ 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; @@ -290,6 +356,7 @@ namespace Ink_Canvas.Windows.SettingsViews { double val = ViewboxFloatingBarScaleTransformValueSlider.Value; ViewboxFloatingBarScaleTransformValueText.Text = val.ToString("F2"); + // 调用 MainWindow 中的方法(会自动检查主题更新) MainWindowSettingsHelper.InvokeSliderValueChanged("ViewboxFloatingBarScaleTransformValueSlider", val); } } @@ -301,6 +368,7 @@ namespace Ink_Canvas.Windows.SettingsViews { double val = ViewboxFloatingBarOpacityValueSlider.Value; ViewboxFloatingBarOpacityValueText.Text = val.ToString("F2"); + // 调用 MainWindow 中的方法(会自动检查主题更新) MainWindowSettingsHelper.InvokeSliderValueChanged("ViewboxFloatingBarOpacityValueSlider", val); } } @@ -312,10 +380,14 @@ 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; @@ -330,47 +402,60 @@ 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 @@ -391,11 +476,31 @@ namespace Ink_Canvas.Windows.SettingsViews var button = this.FindDescendantByName($"{group}{buttonNames[i]}Border") as Border; if (button != null) { - ThemeHelper.SetOptionButtonSelectedState(button, i == selectedIndex); + 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; + } + } } } } + /// + /// 选项按钮点击事件处理 + /// private void OptionButton_Click(object sender, RoutedEventArgs e) { if (!_isLoaded) return; @@ -412,6 +517,7 @@ namespace Ink_Canvas.Windows.SettingsViews string group = parts[0]; string value = parts[1]; + // 清除同组其他按钮的选中状态 var parent = border.Parent as Panel; if (parent != null) { @@ -422,13 +528,24 @@ namespace Ink_Canvas.Windows.SettingsViews string childTag = childBorder.Tag?.ToString(); if (!string.IsNullOrEmpty(childTag) && childTag.StartsWith(group + "_")) { - ThemeHelper.SetOptionButtonSelectedState(childBorder, false); + childBorder.Background = new SolidColorBrush(Colors.Transparent); + var textBlock = childBorder.Child as TextBlock; + if (textBlock != null) + { + textBlock.FontWeight = FontWeights.Normal; + } } } } } - ThemeHelper.SetOptionButtonSelectedState(border, true); + // 设置当前按钮为选中状态 + border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225)); + var currentTextBlock = border.Child as TextBlock; + if (currentTextBlock != null) + { + currentTextBlock.FontWeight = FontWeights.Bold; + } var appearance = MainWindow.Settings.Appearance; if (appearance == null) return; @@ -436,6 +553,7 @@ namespace Ink_Canvas.Windows.SettingsViews switch (group) { case "Theme": + // 通过 MainWindowSettingsHelper 调用 ComboBoxTheme 的 SelectionChanged 事件处理器 try { var mainWindow = Application.Current.MainWindow as MainWindow; @@ -444,22 +562,23 @@ namespace Ink_Canvas.Windows.SettingsViews var comboBox = mainWindow.FindName("ComboBoxTheme") as System.Windows.Controls.ComboBox; if (comboBox != null) { - int themeIndex; - switch (value) - { - case "Light": - themeIndex = 0; - break; - case "Dark": - themeIndex = 1; - break; - case "System": - themeIndex = 2; - break; - default: - themeIndex = 2; - break; - } + // 根据 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; + } if (comboBox.Items.Count > themeIndex) { @@ -467,18 +586,21 @@ 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) { @@ -500,14 +622,15 @@ 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; @@ -531,6 +654,7 @@ namespace Ink_Canvas.Windows.SettingsViews sourceIndex = 3; break; } + // 调用 MainWindow 中的方法 var mainWindow6 = Application.Current.MainWindow as MainWindow; if (mainWindow6 != null) { @@ -542,9 +666,10 @@ namespace Ink_Canvas.Windows.SettingsViews } else { + // 如果找不到控件,直接更新设置 MainWindowSettingsHelper.UpdateSettingDirectly(() => { - appearance.ChickenSoupSource = sourceIndex; + appearance.ChickenSoupSource = sourceIndex; }, "ComboBoxChickenSoupSource"); } } @@ -564,6 +689,7 @@ namespace Ink_Canvas.Windows.SettingsViews imgType = 0; break; } + // 调用 MainWindow 中的方法(带主题检查) var mainWindow3 = Application.Current.MainWindow as MainWindow; if (mainWindow3 != null) { @@ -575,9 +701,10 @@ namespace Ink_Canvas.Windows.SettingsViews } else { + // 如果找不到控件,直接更新设置并通知主题更新 MainWindowSettingsHelper.UpdateSettingSafely(() => { - appearance.UnFoldButtonImageType = imgType; + appearance.UnFoldButtonImageType = imgType; }, "ComboBoxUnFoldBtnImg_SelectionChanged", "ComboBoxUnFoldBtnImg"); MainWindowSettingsHelper.NotifyThemeUpdateIfNeeded("ComboBoxUnFoldBtnImg"); } @@ -598,6 +725,7 @@ namespace Ink_Canvas.Windows.SettingsViews displayMode = 1; break; } + // 调用 MainWindow 中的方法 var mainWindow4 = Application.Current.MainWindow as MainWindow; if (mainWindow4 != null) { @@ -609,9 +737,10 @@ namespace Ink_Canvas.Windows.SettingsViews } else { + // 如果找不到控件,直接更新设置 MainWindowSettingsHelper.UpdateSettingDirectly(() => { - appearance.QuickColorPaletteDisplayMode = displayMode; + appearance.QuickColorPaletteDisplayMode = displayMode; }, "ComboBoxQuickColorPaletteDisplayMode"); } } @@ -637,6 +766,7 @@ namespace Ink_Canvas.Windows.SettingsViews eraserOption = 0; break; } + // 调用 MainWindow 中的方法 var mainWindow5 = Application.Current.MainWindow as MainWindow; if (mainWindow5 != null) { @@ -648,9 +778,10 @@ namespace Ink_Canvas.Windows.SettingsViews } else { + // 如果找不到控件,直接更新设置 MainWindowSettingsHelper.UpdateSettingDirectly(() => { - appearance.EraserDisplayOption = eraserOption; + appearance.EraserDisplayOption = eraserOption; }, "ComboBoxEraserDisplayOption"); } } @@ -658,46 +789,18 @@ 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}"); - } - } - - 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); + System.Diagnostics.Debug.WriteLine($"ThemePanel 应用主题时出错: {ex.Message}"); } } } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/TimerPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/TimerPanel.xaml.cs index f0681123..71f4322b 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)