diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs
index 7ef88b97..08d3f55b 100644
--- a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs
+++ b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs
@@ -1,4 +1,6 @@
using Ink_Canvas.Helpers;
+using Ink_Canvas.Windows;
+using Ink_Canvas.Windows.SettingsViews;
using iNKORE.UI.WPF.Modern;
using System;
using System.Diagnostics;
@@ -2874,46 +2876,64 @@ namespace Ink_Canvas
private void BtnSettings_Click(object sender, RoutedEventArgs e)
{
- if (BorderSettings.Visibility == Visibility.Visible)
+ if (isOpeningOrHidingSettingsPane) return;
+ HideSubPanels();
{
- HideSubPanels();
+ var settingsWindow = new SettingsWindow();
+ settingsWindow.Owner = this;
+ settingsWindow.ShowDialog();
}
- else
+ }
+
+ ///
+ /// 显示老设置面板
+ ///
+ public void ShowOldSettingsPanel()
+ {
+ if (isOpeningOrHidingSettingsPane) return;
+ HideSubPanels();
+
+ // 关闭新设置窗口
+ foreach (Window window in Application.Current.Windows)
{
- BorderSettings.Visibility = Visibility.Visible;
- wasNoFocusModeBeforeSettings = Settings.Advanced.IsNoFocusMode;
- userChangedNoFocusModeInSettings = false; // 重置用户修改标志
- if (wasNoFocusModeBeforeSettings)
+ if (window is SettingsWindow)
{
- isTemporarilyDisablingNoFocusMode = true;
- ApplyNoFocusMode();
+ window.Close();
+ break;
}
-
- // 设置蒙版为可点击,并添加半透明背景
+ }
+
+ // 显示老设置面板
+ if (BorderSettings.Visibility != Visibility.Visible)
+ {
+ isOpeningOrHidingSettingsPane = true;
+ BorderSettings.Visibility = Visibility.Visible;
+ BorderSettingsMask.Visibility = Visibility.Visible;
BorderSettingsMask.IsHitTestVisible = true;
- BorderSettingsMask.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
- SettingsPanelScrollViewer.ScrollToTop();
+ BorderSettingsMask.Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0));
+
+ // 设置初始位置
+ BorderSettings.RenderTransform = new TranslateTransform(490, 0);
+
var sb = new Storyboard();
-
- // 滑动动画
var slideAnimation = new DoubleAnimation
{
- From = BorderSettings.RenderTransform.Value.OffsetX - 490, // 滑动距离
+ From = 490,
To = 0,
Duration = TimeSpan.FromSeconds(0.6),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
};
Storyboard.SetTargetProperty(slideAnimation,
new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.X)"));
-
+ Storyboard.SetTarget(slideAnimation, BorderSettings);
+
sb.Children.Add(slideAnimation);
-
- sb.Completed += (s, _) => { isOpeningOrHidingSettingsPane = false; };
-
- BorderSettings.RenderTransform = new TranslateTransform();
-
- isOpeningOrHidingSettingsPane = true;
- sb.Begin(BorderSettings);
+ sb.Completed += (s, _) =>
+ {
+ isOpeningOrHidingSettingsPane = false;
+ };
+
+ sb.Begin();
}
}
diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs
index 312076e7..a9644fdf 100644
--- a/Ink Canvas/MainWindow_cs/MW_Settings.cs
+++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs
@@ -2750,7 +2750,7 @@ namespace Ink_Canvas
Settings.Startup.IsFoldAtStartup = false;
}
- private void BtnResetToSuggestion_Click(object sender, RoutedEventArgs e)
+ public void BtnResetToSuggestion_Click(object sender, RoutedEventArgs e)
{
try
{
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AboutPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/AboutPanel.xaml.cs
index 3eef3a4a..ec925479 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AboutPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AboutPanel.xaml.cs
@@ -259,5 +259,20 @@ namespace Ink_Canvas.Windows.SettingsViews
var border = thumb.Template.FindName("ScrollbarThumbEx", thumb);
((Border)border).Background = new SolidColorBrush(Color.FromRgb(138, 138, 138));
}
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"AboutPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml
index 36ca62eb..f5a51a09 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml
@@ -37,7 +37,7 @@
-
+
@@ -52,7 +52,7 @@
-
+
@@ -62,7 +62,7 @@
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs
index 1269c359..cd0757df 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AdvancedPanel.xaml.cs
@@ -1,6 +1,11 @@
+using Ink_Canvas;
+using iNKORE.UI.WPF.Helpers;
using System;
+using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Media;
+using Application = System.Windows.Application;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -9,9 +14,41 @@ namespace Ink_Canvas.Windows.SettingsViews
///
public partial class AdvancedPanel : UserControl
{
+ private bool _isLoaded = false;
+
public AdvancedPanel()
{
InitializeComponent();
+ Loaded += AdvancedPanel_Loaded;
+ }
+
+ private void AdvancedPanel_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ // 添加触摸支持
+ EnableTouchSupport();
+ // 应用主题
+ ApplyTheme();
+ _isLoaded = true;
+ }
+
+ ///
+ /// 为面板中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupport()
+ {
+ try
+ {
+ // 延迟执行,确保所有控件都已加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ MainWindowSettingsHelper.EnableTouchSupportForControls(this);
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"AdvancedPanel 启用触摸支持时出错: {ex.Message}");
+ }
}
public event EventHandler IsTopBarNeedShadowEffect;
@@ -29,6 +66,442 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 加载设置到UI
+ ///
+ public void LoadSettings()
+ {
+ if (MainWindow.Settings == null || MainWindow.Settings.Advanced == null) return;
+
+ _isLoaded = false;
+
+ try
+ {
+ var advanced = MainWindow.Settings.Advanced;
+
+ // 特殊屏幕模式
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsSpecialScreen"), advanced.IsSpecialScreen);
+
+ // 触摸倍数
+ if (TouchMultiplierSlider != null)
+ {
+ TouchMultiplierSlider.Value = advanced.TouchMultiplier;
+ if (TouchMultiplierText != null)
+ {
+ TouchMultiplierText.Text = advanced.TouchMultiplier.ToString("F2");
+ }
+ }
+
+ // 橡皮擦绑定触摸大小倍数
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEraserBindTouchMultiplier"), advanced.EraserBindTouchMultiplier);
+
+ // 笔尖模式 BoundsWidth
+ if (NibModeBoundsWidthSlider != null)
+ {
+ NibModeBoundsWidthSlider.Value = advanced.NibModeBoundsWidth;
+ if (NibModeBoundsWidthText != null)
+ {
+ NibModeBoundsWidthText.Text = advanced.NibModeBoundsWidth.ToString();
+ }
+ }
+
+ // 手指模式 BoundsWidth
+ if (FingerModeBoundsWidthSlider != null)
+ {
+ FingerModeBoundsWidthSlider.Value = advanced.FingerModeBoundsWidth;
+ if (FingerModeBoundsWidthText != null)
+ {
+ FingerModeBoundsWidthText.Text = advanced.FingerModeBoundsWidth.ToString();
+ }
+ }
+
+ // 四边红外模式
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsQuadIR"), advanced.IsQuadIR);
+
+ // 记录日志
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsLogEnabled"), advanced.IsLogEnabled);
+
+ // 日志以日期保存
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsSaveLogByDate"), advanced.IsSaveLogByDate);
+
+ // 关闭软件时二次弹窗确认
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsSecondConfimeWhenShutdownApp"), advanced.IsSecondConfirmWhenShutdownApp);
+
+ // 实验性功能
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsEnableFullScreenHelper"), advanced.IsEnableFullScreenHelper);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsEnableAvoidFullScreenHelper"), advanced.IsEnableAvoidFullScreenHelper);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsEnableEdgeGestureUtil"), advanced.IsEnableEdgeGestureUtil);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsEnableForceFullScreen"), advanced.IsEnableForceFullScreen);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsEnableDPIChangeDetection"), advanced.IsEnableDPIChangeDetection);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsEnableResolutionChangeDetection"), advanced.IsEnableResolutionChangeDetection);
+
+ // 备份设置
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsAutoBackupBeforeUpdate"), advanced.IsAutoBackupBeforeUpdate);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchIsAutoBackupEnabled"), advanced.IsAutoBackupEnabled);
+ SetOptionButtonState("AutoBackupInterval", advanced.AutoBackupIntervalDays);
+
+ // 悬浮窗拦截
+ // 注意:IsEnableFloatingWindowInterception 可能不在 Advanced 类中,需要确认
+ // 这里先假设它在 Advanced 类中,如果不在,需要调整
+ }
+ catch (Exception ex)
+ {
+ 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));
+ var innerBorder = toggleSwitch.Child as Border;
+ if (innerBorder != null)
+ {
+ innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
+ }
+ }
+
+ ///
+ /// 设置选项按钮状态
+ ///
+ private void SetOptionButtonState(string group, int selectedValue)
+ {
+ var buttons = new Dictionary>
+ {
+ { "AutoBackupInterval", new Dictionary { { 1, "1Day" }, { 3, "3Days" }, { 7, "7Days" }, { 14, "14Days" }, { 30, "30Days" } } }
+ };
+
+ if (!buttons.ContainsKey(group)) return;
+
+ var buttonNames = buttons[group];
+ if (!buttonNames.ContainsKey(selectedValue)) return;
+
+ string buttonName = buttonNames[selectedValue];
+ var button = this.FindDescendantByName($"{group}{buttonName}Border") as Border;
+ if (button != null)
+ {
+ // 清除同组其他按钮的选中状态
+ var parent = button.Parent as Panel;
+ if (parent != null)
+ {
+ foreach (var child in parent.Children)
+ {
+ if (child is Border childBorder && childBorder != button)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ // 设置当前按钮为选中状态
+ button.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ var currentTextBlock = button.Child as TextBlock;
+ if (currentTextBlock != null)
+ {
+ currentTextBlock.FontWeight = FontWeights.Bold;
+ }
+ }
+ }
+
+ ///
+ /// ToggleSwitch点击事件处理
+ ///
+ private void ToggleSwitch_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ bool isOn = border.Background.ToString() == "#FF3584E4";
+ bool newState = !isOn;
+ SetToggleSwitchState(border, newState);
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ var advanced = MainWindow.Settings.Advanced;
+ if (advanced == null) return;
+
+ switch (tag)
+ {
+ case "IsSpecialScreen":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsSpecialScreen", newState);
+ break;
+
+ case "EraserBindTouchMultiplier":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEraserBindTouchMultiplier", newState);
+ break;
+
+ case "IsQuadIR":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsQuadIR", newState);
+ break;
+
+ case "IsLogEnabled":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsLogEnabled", newState);
+ break;
+
+ case "IsSaveLogByDate":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsSaveLogByDate", newState);
+ break;
+
+ case "IsSecondConfirmWhenShutdownApp":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsSecondConfimeWhenShutdownApp", newState);
+ break;
+
+ case "IsEnableFullScreenHelper":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsEnableFullScreenHelper", newState);
+ break;
+
+ case "IsEnableAvoidFullScreenHelper":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsEnableAvoidFullScreenHelper", newState);
+ break;
+
+ case "IsEnableEdgeGestureUtil":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsEnableEdgeGestureUtil", newState);
+ break;
+
+ case "IsEnableForceFullScreen":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsEnableForceFullScreen", newState);
+ break;
+
+ case "IsEnableDPIChangeDetection":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsEnableDPIChangeDetection", newState);
+ break;
+
+ case "IsEnableResolutionChangeDetection":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsEnableResolutionChangeDetection", newState);
+ break;
+
+ case "IsAutoBackupBeforeUpdate":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsAutoBackupBeforeUpdate", newState);
+ break;
+
+ case "IsAutoBackupEnabled":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsAutoBackupEnabled", newState);
+ break;
+ }
+ }
+
+ ///
+ /// Slider值变化事件处理
+ ///
+ private void TouchMultiplierSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (TouchMultiplierSlider != null && TouchMultiplierText != null)
+ {
+ double value = TouchMultiplierSlider.Value;
+ TouchMultiplierText.Text = value.ToString("F2");
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("TouchMultiplierSlider", value);
+ }
+ }
+
+ private void NibModeBoundsWidthSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (NibModeBoundsWidthSlider != null && NibModeBoundsWidthText != null)
+ {
+ double value = NibModeBoundsWidthSlider.Value;
+ NibModeBoundsWidthText.Text = ((int)value).ToString();
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("NibModeBoundsWidthSlider", value);
+ }
+ }
+
+ private void FingerModeBoundsWidthSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (FingerModeBoundsWidthSlider != null && FingerModeBoundsWidthText != null)
+ {
+ double value = FingerModeBoundsWidthSlider.Value;
+ FingerModeBoundsWidthText.Text = ((int)value).ToString();
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("FingerModeBoundsWidthSlider", value);
+ }
+ }
+
+ ///
+ /// 选项按钮点击事件处理
+ ///
+ private void OptionButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ string[] parts = tag.Split('_');
+ if (parts.Length < 2) return;
+
+ string group = parts[0];
+ string value = parts[1];
+
+ // 清除同组其他按钮的选中状态
+ var parent = border.Parent as Panel;
+ if (parent != null)
+ {
+ foreach (var child in parent.Children)
+ {
+ if (child is Border childBorder && childBorder != border)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ // 设置当前按钮为选中状态
+ border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ var currentTextBlock = border.Child as TextBlock;
+ if (currentTextBlock != null)
+ {
+ currentTextBlock.FontWeight = FontWeights.Bold;
+ }
+
+ if (MainWindow.Settings.Advanced == null) return;
+
+ switch (group)
+ {
+ case "AutoBackupInterval":
+ int days;
+ if (int.TryParse(value, out days))
+ {
+ // 尝试调用 MainWindow 中的方法
+ var mainWindow = Application.Current.MainWindow as MainWindow;
+ if (mainWindow != null)
+ {
+ var comboBox = mainWindow.FindName("ComboBoxAutoBackupInterval") as System.Windows.Controls.ComboBox;
+ if (comboBox != null)
+ {
+ // 找到对应的选项并设置
+ foreach (ComboBoxItem item in comboBox.Items)
+ {
+ if (item.Tag != null && int.TryParse(item.Tag.ToString(), out int tagValue) && tagValue == days)
+ {
+ comboBox.SelectedItem = item;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxAutoBackupInterval", item);
+ break;
+ }
+ }
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ MainWindow.Settings.Advanced.AutoBackupIntervalDays = days;
+ }, "ComboBoxAutoBackupInterval");
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ ///
+ /// 按钮点击事件处理(备份还原、文件关联等)
+ ///
+ private void Button_Click(object sender, RoutedEventArgs e)
+ {
+ var button = sender as Button;
+ if (button == null) return;
+
+ string name = button.Name;
+ // 这些按钮的功能可能需要调用 MainWindow 中的方法
+ // 暂时先留空,后续可以根据需要实现
+ switch (name)
+ {
+ case "BtnManualBackup":
+ // TODO: 调用 MainWindow 的备份方法
+ break;
+
+ case "BtnRestoreBackup":
+ // TODO: 调用 MainWindow 的还原方法
+ break;
+
+ case "BtnUnregisterFileAssociation":
+ // TODO: 调用 MainWindow 的取消文件关联方法
+ break;
+
+ case "BtnCheckFileAssociation":
+ // TODO: 调用 MainWindow 的检查文件关联方法
+ break;
+
+ case "BtnRegisterFileAssociation":
+ // TODO: 调用 MainWindow 的注册文件关联方法
+ break;
+
+ case "BtnDlassSettingsManage":
+ // TODO: 调用 MainWindow 的 Dlass 设置管理方法
+ break;
+ }
+ }
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"AdvancedPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
-
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AppearancePanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/AppearancePanel.xaml.cs
index 0a3cefd7..9e331498 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AppearancePanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AppearancePanel.xaml.cs
@@ -29,5 +29,20 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"AppearancePanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml
index 9a6e26c3..d5999941 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml
@@ -43,7 +43,7 @@
-
+
@@ -54,7 +54,7 @@
-
+
@@ -65,7 +65,7 @@
-
+
@@ -76,7 +76,7 @@
-
+
@@ -88,7 +88,7 @@
-
+
@@ -99,7 +99,7 @@
-
+
@@ -110,7 +110,7 @@
-
+
@@ -121,7 +121,7 @@
-
+
@@ -133,7 +133,7 @@
-
+
@@ -144,7 +144,7 @@
-
+
@@ -155,7 +155,7 @@
-
+
@@ -166,7 +166,7 @@
-
+
@@ -178,7 +178,7 @@
-
+
@@ -189,7 +189,7 @@
-
+
@@ -200,7 +200,7 @@
-
+
@@ -211,7 +211,7 @@
-
+
@@ -226,7 +226,7 @@
-
+
@@ -240,7 +240,7 @@
-
+
@@ -254,7 +254,7 @@
-
+
@@ -268,7 +268,7 @@
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs
index fc0258e7..775be208 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AutomationPanel.xaml.cs
@@ -1,6 +1,7 @@
using System;
using System.Windows;
using System.Windows.Controls;
+using Ink_Canvas.Windows.SettingsViews;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -9,9 +10,129 @@ namespace Ink_Canvas.Windows.SettingsViews
///
public partial class AutomationPanel : UserControl
{
+ private bool _isLoaded = false;
+
public AutomationPanel()
{
InitializeComponent();
+ Loaded += AutomationPanel_Loaded;
+ }
+
+ private void AutomationPanel_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ // 添加触摸支持
+ EnableTouchSupport();
+ // 应用主题
+ ApplyTheme();
+ _isLoaded = true;
+ }
+
+ ///
+ /// 加载设置
+ ///
+ private void LoadSettings()
+ {
+ try
+ {
+ if (MainWindow.Settings == null || MainWindow.Settings.Automation == null) return;
+
+ _isLoaded = false;
+
+ var automation = MainWindow.Settings.Automation;
+
+ // 设置所有 ToggleSwitch 的状态
+ SetToggleSwitchState("ToggleSwitchAutoFoldInEasiNote", automation.IsAutoFoldInEasiNote);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInEasiCamera", automation.IsAutoFoldInEasiCamera);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInHiteTouchPro", automation.IsAutoFoldInHiteTouchPro);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInEasiNote3", automation.IsAutoFoldInEasiNote3);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInEasiNote3C", automation.IsAutoFoldInEasiNote3C);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInEasiNote5C", automation.IsAutoFoldInEasiNote5C);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInSeewoPincoTeacher", automation.IsAutoFoldInSeewoPincoTeacher);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInHiteCamera", automation.IsAutoFoldInHiteCamera);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInHiteLightBoard", automation.IsAutoFoldInHiteLightBoard);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInWxBoardMain", automation.IsAutoFoldInWxBoardMain);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInMSWhiteboard", automation.IsAutoFoldInMSWhiteboard);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInAdmoxWhiteboard", automation.IsAutoFoldInAdmoxWhiteboard);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInAdmoxBooth", automation.IsAutoFoldInAdmoxBooth);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInQPoint", automation.IsAutoFoldInQPoint);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInYiYunVisualPresenter", automation.IsAutoFoldInYiYunVisualPresenter);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInMaxHubWhiteboard", automation.IsAutoFoldInMaxHubWhiteboard);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInPPTSlideShow", automation.IsAutoFoldInPPTSlideShow);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInEasiNoteIgnoreDesktopAnno", automation.IsAutoFoldInEasiNoteIgnoreDesktopAnno);
+ SetToggleSwitchState("ToggleSwitchAutoFoldInOldZyBoard", automation.IsAutoFoldInOldZyBoard);
+ SetToggleSwitchState("ToggleSwitchKeepFoldAfterSoftwareExit", automation.KeepFoldAfterSoftwareExit);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"AutomationPanel 加载设置时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 设置 ToggleSwitch 状态
+ ///
+ private void SetToggleSwitchState(string name, bool isOn)
+ {
+ try
+ {
+ var border = FindName(name) as System.Windows.Controls.Border;
+ if (border != 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;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"AutomationPanel 设置 ToggleSwitch {name} 状态时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// ToggleSwitch 点击事件处理
+ ///
+ private void ToggleSwitch_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as System.Windows.Controls.Border;
+ if (border == null) return;
+
+ bool currentState = border.Background.ToString().Contains("3584e4");
+ bool newState = !currentState;
+ SetToggleSwitchState(border.Name, newState);
+
+ // 通过 MainWindowSettingsHelper 调用 MainWindow 中的方法
+ string toggleSwitchName = border.Name;
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled(toggleSwitchName, newState);
+ }
+
+ ///
+ /// 为面板中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupport()
+ {
+ try
+ {
+ // 延迟执行,确保所有控件都已加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ MainWindowSettingsHelper.EnableTouchSupportForControls(this);
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"AutomationPanel 启用触摸支持时出错: {ex.Message}");
+ }
}
public event EventHandler IsTopBarNeedShadowEffect;
@@ -29,6 +150,21 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"AutomationPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml
index a7207026..5201d4e1 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml
@@ -35,7 +35,7 @@
-
+
@@ -49,7 +49,7 @@
-
+
@@ -63,7 +63,7 @@
-
+
@@ -77,19 +77,19 @@
-
+
-
+
-
+
-
+
-
+
@@ -105,7 +105,7 @@
-
+
@@ -119,7 +119,7 @@
-
+
@@ -133,7 +133,7 @@
-
+
@@ -147,7 +147,7 @@
-
+
@@ -166,13 +166,13 @@
-
+
-
+
-
+
@@ -183,7 +183,7 @@
-
+
@@ -197,7 +197,7 @@
-
+
@@ -211,7 +211,7 @@
-
+
@@ -230,7 +230,7 @@
-
+
@@ -245,7 +245,7 @@
-
+
@@ -261,7 +261,7 @@
-
+
@@ -276,25 +276,25 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -309,7 +309,7 @@
-
+
@@ -323,7 +323,7 @@
-
+
@@ -341,7 +341,7 @@
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml.cs
index ee6180c8..63db2229 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml.cs
@@ -1,10 +1,12 @@
+using Ink_Canvas;
+using iNKORE.UI.WPF.Helpers;
using System;
+using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
-using iNKORE.UI.WPF.Helpers;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -13,9 +15,41 @@ namespace Ink_Canvas.Windows.SettingsViews
///
public partial class CanvasAndInkPanel : UserControl
{
+ private bool _isLoaded = false;
+
public CanvasAndInkPanel()
{
InitializeComponent();
+ Loaded += CanvasAndInkPanel_Loaded;
+ }
+
+ private void CanvasAndInkPanel_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ // 添加触摸支持
+ EnableTouchSupport();
+ // 应用主题
+ ApplyTheme();
+ _isLoaded = true;
+ }
+
+ ///
+ /// 为面板中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupport()
+ {
+ try
+ {
+ // 延迟执行,确保所有控件都已加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ MainWindowSettingsHelper.EnableTouchSupportForControls(this);
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"CanvasAndInkPanel 启用触摸支持时出错: {ex.Message}");
+ }
}
public event EventHandler IsTopBarNeedShadowEffect;
@@ -33,6 +67,541 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 加载设置到UI
+ ///
+ public void LoadSettings()
+ {
+ if (MainWindow.Settings == null || MainWindow.Settings.Canvas == null) return;
+
+ _isLoaded = false;
+
+ try
+ {
+ var canvas = MainWindow.Settings.Canvas;
+
+ // 显示画笔光标
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchShowCursor"), canvas.IsShowCursor);
+
+ // 启用压感触屏模式
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnablePressureTouchMode"), canvas.EnablePressureTouchMode);
+
+ // 屏蔽压感
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchDisablePressure"), canvas.DisablePressure);
+
+ // 板擦橡皮大小
+ SetOptionButtonState("EraserSize", canvas.EraserSize);
+
+ // 退出画板模式后隐藏墨迹
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchHideStrokeWhenSelecting"), canvas.HideStrokeWhenSelecting);
+
+ // 清空墨迹时删除墨迹历史记录
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchClearCanvasAndClearTimeMachine"), canvas.ClearCanvasAndClearTimeMachine);
+
+ // 清空画布时同时清空图片
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchClearCanvasAlsoClearImages"), canvas.ClearCanvasAlsoClearImages);
+
+ // 插入图片时自动压缩
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchCompressPicturesUploaded"), canvas.IsCompressPicturesUploaded);
+
+ // 保留双曲线渐近线
+ SetOptionButtonState("HyperbolaAsymptote", (int)canvas.HyperbolaAsymptoteOption);
+
+ // 绘制圆时显示圆心位置
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchShowCircleCenter"), canvas.ShowCircleCenter);
+
+ // 使用WPF默认贝塞尔曲线平滑
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchFitToCurve"), canvas.FitToCurve && !canvas.UseAdvancedBezierSmoothing);
+
+ // 使用高级贝塞尔曲线平滑
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAdvancedBezierSmoothing"), canvas.UseAdvancedBezierSmoothing);
+
+ // 启用异步墨迹平滑
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchUseAsyncInkSmoothing"), canvas.UseAsyncInkSmoothing);
+
+ // 启用硬件加速
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchUseHardwareAcceleration"), canvas.UseHardwareAcceleration);
+
+ // 启用直线自动拉直
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoStraightenLine"), canvas.AutoStraightenLine);
+
+ // 启用高精度直线拉直
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchHighPrecisionLineStraighten"), canvas.HighPrecisionLineStraighten);
+
+ // 启用直线端点吸附
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchLineEndpointSnapping"), canvas.LineEndpointSnapping);
+
+ // 启用墨迹渐隐功能
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableInkFade"), canvas.EnableInkFade);
+ if (InkFadeTimePanel != null)
+ {
+ InkFadeTimePanel.Visibility = canvas.EnableInkFade ? Visibility.Visible : Visibility.Collapsed;
+ }
+ if (InkFadeTimeSlider != null)
+ {
+ InkFadeTimeSlider.Value = canvas.InkFadeTime;
+ }
+
+ // 定时自动保存墨迹
+ // 注意:这个设置可能在 Automation 或 Canvas 中,需要根据实际情况调整
+ // SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableAutoSaveStrokes"), ...);
+
+ // 墨迹全页面保存
+ // SetToggleSwitchState(FindToggleSwitch("ToggleSwitchSaveFullPageStrokes"), ...);
+
+ // 保存为XML格式
+ // SetToggleSwitchState(FindToggleSwitch("ToggleSwitchSaveStrokesAsXML"), ...);
+
+ // 自动保存幻灯片墨迹
+ if (MainWindow.Settings.PowerPointSettings != null)
+ {
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoSaveStrokesInPowerPoint"),
+ MainWindow.Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint);
+ }
+ }
+ catch (Exception ex)
+ {
+ 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));
+ var innerBorder = toggleSwitch.Child as Border;
+ if (innerBorder != null)
+ {
+ innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
+ }
+ }
+
+ ///
+ /// 设置选项按钮状态
+ ///
+ private void SetOptionButtonState(string group, int selectedIndex)
+ {
+ var buttons = new[] { "VerySmall", "Small", "Medium", "Large", "VeryLarge" };
+ var hyperbolaButtons = new[] { "Yes", "No", "Ask" };
+
+ string[] buttonNames = group == "EraserSize" ? buttons : hyperbolaButtons;
+
+ for (int i = 0; i < buttonNames.Length && i <= selectedIndex; i++)
+ {
+ var button = this.FindDescendantByName($"{group}{buttonNames[i]}") 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;
+ }
+ }
+ }
+ }
+ }
+
+ ///
+ /// ToggleSwitch点击事件处理
+ ///
+ private void ToggleSwitch_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ bool isOn = border.Background.ToString() == "#FF3584E4";
+ bool newState = !isOn;
+ SetToggleSwitchState(border, newState);
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ var canvas = MainWindow.Settings.Canvas;
+ if (canvas == null) return;
+
+ switch (tag)
+ {
+ case "ShowCursor":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchShowCursor", newState);
+ break;
+
+ case "EnablePressureTouchMode":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnablePressureTouchMode", newState);
+ // 处理互斥逻辑
+ if (newState && canvas.DisablePressure)
+ {
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchDisablePressure", false);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchDisablePressure"), false);
+ }
+ break;
+
+ case "DisablePressure":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchDisablePressure", newState);
+ // 处理互斥逻辑
+ if (newState && canvas.EnablePressureTouchMode)
+ {
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnablePressureTouchMode", false);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnablePressureTouchMode"), false);
+ }
+ break;
+
+ case "HideStrokeWhenSelecting":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchHideStrokeWhenSelecting", newState);
+ break;
+
+ case "ClearCanvasAndClearTimeMachine":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchClearCanvasAndClearTimeMachine", newState);
+ break;
+
+ case "ClearCanvasAlsoClearImages":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchClearCanvasAlsoClearImages", newState);
+ break;
+
+ case "CompressPicturesUploaded":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchCompressPicturesUploaded", newState);
+ break;
+
+ case "ShowCircleCenter":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchShowCircleCenter", newState);
+ break;
+
+ case "FitToCurve":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchFitToCurve", newState);
+ // 处理互斥逻辑
+ if (newState)
+ {
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAdvancedBezierSmoothing", false);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAdvancedBezierSmoothing"), false);
+ }
+ break;
+
+ case "AdvancedBezierSmoothing":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAdvancedBezierSmoothing", newState);
+ // 处理互斥逻辑
+ if (newState)
+ {
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchFitToCurve", false);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchFitToCurve"), false);
+ }
+ break;
+
+ case "UseAsyncInkSmoothing":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAsyncInkSmoothing", newState);
+ break;
+
+ case "UseHardwareAcceleration":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchHardwareAcceleration", newState);
+ break;
+
+ case "AutoStraightenLine":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoStraightenLine", newState);
+ break;
+
+ case "HighPrecisionLineStraighten":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchHighPrecisionLineStraighten", newState);
+ break;
+
+ case "LineEndpointSnapping":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchLineEndpointSnapping", newState);
+ break;
+
+ case "EnableInkFade":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableInkFade", newState);
+ // 更新UI状态
+ if (InkFadeTimePanel != null)
+ {
+ InkFadeTimePanel.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
+ }
+ break;
+
+ case "EnableAutoSaveStrokes":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableAutoSaveStrokes", newState);
+ break;
+
+ case "SaveFullPageStrokes":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchSaveFullPageStrokes", newState);
+ break;
+
+ case "SaveStrokesAsXML":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchSaveStrokesAsXML", newState);
+ break;
+
+ case "AutoSaveStrokesInPowerPoint":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoSaveStrokesInPowerPoint", newState);
+ break;
+ }
+ }
+
+ ///
+ /// 选项按钮点击事件处理
+ ///
+ private void OptionButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ string[] parts = tag.Split('_');
+ if (parts.Length < 2) return;
+
+ string group = parts[0];
+ string value = parts[1];
+
+ // 清除同组其他按钮的选中状态
+ var parent = border.Parent as Panel;
+ if (parent != null)
+ {
+ foreach (var child in parent.Children)
+ {
+ if (child is Border childBorder && childBorder != border)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ // 设置当前按钮为选中状态
+ border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ var currentTextBlock = border.Child as TextBlock;
+ if (currentTextBlock != null)
+ {
+ currentTextBlock.FontWeight = FontWeights.Bold;
+ }
+
+ var canvas = MainWindow.Settings.Canvas;
+ if (canvas == null) return;
+
+ switch (group)
+ {
+ case "EraserSize":
+ int eraserSize;
+ switch (value)
+ {
+ case "VerySmall":
+ eraserSize = 0;
+ break;
+ case "Small":
+ eraserSize = 1;
+ break;
+ case "Medium":
+ eraserSize = 2;
+ break;
+ case "Large":
+ eraserSize = 3;
+ break;
+ case "VeryLarge":
+ eraserSize = 4;
+ break;
+ default:
+ eraserSize = 2;
+ break;
+ }
+ // 调用 MainWindow 中的方法
+ var mainWindow = Application.Current.MainWindow as MainWindow;
+ if (mainWindow != null)
+ {
+ var comboBox = mainWindow.FindName("ComboBoxEraserSize") as System.Windows.Controls.ComboBox;
+ if (comboBox != null && comboBox.Items.Count > eraserSize)
+ {
+ comboBox.SelectedIndex = eraserSize;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxEraserSize", comboBox.Items[eraserSize]);
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ canvas.EraserSize = eraserSize;
+ }, "ComboBoxEraserSize");
+ }
+ }
+ break;
+
+ case "HyperbolaAsymptote":
+ OptionalOperation option;
+ switch (value)
+ {
+ case "Yes":
+ option = OptionalOperation.Yes;
+ break;
+ case "No":
+ option = OptionalOperation.No;
+ break;
+ case "Ask":
+ option = OptionalOperation.Ask;
+ break;
+ default:
+ option = OptionalOperation.Ask;
+ break;
+ }
+ // 调用 MainWindow 中的方法
+ var mainWindow2 = Application.Current.MainWindow as MainWindow;
+ if (mainWindow2 != null)
+ {
+ var comboBox = mainWindow2.FindName("ComboBoxHyperbolaAsymptoteOption") as System.Windows.Controls.ComboBox;
+ if (comboBox != null)
+ {
+ int optionIndex = (int)option;
+ if (comboBox.Items.Count > optionIndex)
+ {
+ comboBox.SelectedIndex = optionIndex;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxHyperbolaAsymptoteOption", comboBox.Items[optionIndex]);
+ }
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ canvas.HyperbolaAsymptoteOption = option;
+ }, "ComboBoxHyperbolaAsymptoteOption");
+ }
+ }
+ break;
+
+ case "AutoSaveStrokesInterval":
+ // 调用 MainWindow 中的方法
+ int interval = int.Parse(value);
+ var mainWindow3 = Application.Current.MainWindow as MainWindow;
+ if (mainWindow3 != null)
+ {
+ var comboBox = mainWindow3.FindName("ComboBoxAutoSaveStrokesInterval") as System.Windows.Controls.ComboBox;
+ if (comboBox != null)
+ {
+ // 查找对应的选项(根据 Tag 或 Content 匹配)
+ foreach (System.Windows.Controls.ComboBoxItem item in comboBox.Items)
+ {
+ if (item.Tag != null && int.TryParse(item.Tag.ToString(), out int tagValue) && tagValue == interval)
+ {
+ comboBox.SelectedItem = item;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxAutoSaveStrokesInterval", item);
+ break;
+ }
+ else if (item.Content != null && item.Content.ToString().Contains(interval.ToString()))
+ {
+ comboBox.SelectedItem = item;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxAutoSaveStrokesInterval", item);
+ break;
+ }
+ }
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ if (MainWindow.Settings.Automation != null)
+ {
+ MainWindow.Settings.Automation.AutoSaveStrokesIntervalMinutes = interval;
+ }
+ }, "ComboBoxAutoSaveStrokesInterval");
+ }
+ }
+ break;
+ }
+ }
+
+ ///
+ /// 自动保存间隔选项按钮点击事件处理
+ ///
+ private void AutoSaveIntervalButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ OptionButton_Click(sender, e);
+ }
+
+ ///
+ /// Slider值变化事件处理
+ ///
+ private void InkFadeTimeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (InkFadeTimeSlider != null && InkFadeTimeText != null)
+ {
+ double value = InkFadeTimeSlider.Value;
+ InkFadeTimeText.Text = $"{(int)value}ms";
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("InkFadeTimeSlider", value);
+ }
+ }
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"CanvasAndInkPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml.cs
index e7a52197..84768d37 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml.cs
@@ -29,6 +29,21 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"CrashActionPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/FloatingBarDnDSettingsPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/FloatingBarDnDSettingsPanel.xaml.cs
index 724b52b1..8e3f26ce 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/FloatingBarDnDSettingsPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/FloatingBarDnDSettingsPanel.xaml.cs
@@ -1,4 +1,5 @@
using iNKORE.UI.WPF.DragDrop;
+using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows;
@@ -143,5 +144,20 @@ namespace Ink_Canvas.Windows.SettingsViews
IconSource = FindResource("PenIcon") as DrawingImage,
});
}
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"FloatingBarDnDSettingsPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml
index 9798e852..a9955fb4 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml
@@ -35,7 +35,7 @@
-
+
@@ -49,7 +49,7 @@
-
+
@@ -68,7 +68,7 @@
-
+
@@ -77,23 +77,23 @@
-
-
-
-
+
+
+
+
-
-
+
+
-
+
-
+
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml.cs
index d90fc785..5e71f8c2 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/GesturesPanel.xaml.cs
@@ -1,6 +1,11 @@
+using Ink_Canvas;
+using iNKORE.UI.WPF.Helpers;
using System;
+using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Media;
+using Application = System.Windows.Application;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -9,9 +14,41 @@ namespace Ink_Canvas.Windows.SettingsViews
///
public partial class GesturesPanel : UserControl
{
+ private bool _isLoaded = false;
+
public GesturesPanel()
{
InitializeComponent();
+ Loaded += GesturesPanel_Loaded;
+ }
+
+ private void GesturesPanel_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ // 添加触摸支持
+ EnableTouchSupport();
+ // 应用主题
+ ApplyTheme();
+ _isLoaded = true;
+ }
+
+ ///
+ /// 为面板中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupport()
+ {
+ try
+ {
+ // 延迟执行,确保所有控件都已加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ MainWindowSettingsHelper.EnableTouchSupportForControls(this);
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"GesturesPanel 启用触摸支持时出错: {ex.Message}");
+ }
}
public event EventHandler IsTopBarNeedShadowEffect;
@@ -29,6 +66,261 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 加载设置到UI
+ ///
+ public void LoadSettings()
+ {
+ if (MainWindow.Settings == null) return;
+
+ _isLoaded = false;
+
+ try
+ {
+ // 进退白板模式自动开关双指移动功能
+ if (MainWindow.Settings.Gesture != null)
+ {
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoSwitchTwoFingerGesture"), MainWindow.Settings.Gesture.AutoSwitchTwoFingerGesture);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableTwoFingerRotationOnSelection"), MainWindow.Settings.Gesture.IsEnableTwoFingerRotationOnSelection);
+ }
+
+ // 启用手掌擦
+ if (MainWindow.Settings.Canvas != null)
+ {
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnablePalmEraser"), MainWindow.Settings.Canvas.EnablePalmEraser);
+ if (PalmEraserSensitivityPanel != null)
+ {
+ PalmEraserSensitivityPanel.Visibility = MainWindow.Settings.Canvas.EnablePalmEraser ? Visibility.Visible : Visibility.Collapsed;
+ }
+
+ // 手掌擦敏感度
+ SetOptionButtonState("PalmEraserSensitivity", MainWindow.Settings.Canvas.PalmEraserSensitivity);
+ }
+ }
+ catch (Exception ex)
+ {
+ 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));
+ var innerBorder = toggleSwitch.Child as Border;
+ if (innerBorder != null)
+ {
+ innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
+ }
+ }
+
+ ///
+ /// 设置选项按钮状态
+ ///
+ private void SetOptionButtonState(string group, int selectedIndex)
+ {
+ var buttons = new Dictionary
+ {
+ { "PalmEraserSensitivity", new[] { "Low", "Medium", "High" } }
+ };
+
+ if (!buttons.ContainsKey(group)) return;
+
+ string[] buttonNames = buttons[group];
+
+ for (int i = 0; i < buttonNames.Length; i++)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ ///
+ /// ToggleSwitch点击事件处理
+ ///
+ private void ToggleSwitch_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ bool isOn = border.Background.ToString() == "#FF3584E4";
+ bool newState = !isOn;
+ SetToggleSwitchState(border, newState);
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ switch (tag)
+ {
+ case "AutoSwitchTwoFingerGesture":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoSwitchTwoFingerGesture", newState);
+ break;
+
+ case "EnableTwoFingerRotationOnSelection":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableTwoFingerRotationOnSelection", newState);
+ break;
+
+ case "EnablePalmEraser":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnablePalmEraser", newState);
+ // 更新UI状态
+ if (PalmEraserSensitivityPanel != null)
+ {
+ PalmEraserSensitivityPanel.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
+ }
+ break;
+ }
+ }
+
+ ///
+ /// 选项按钮点击事件处理
+ ///
+ private void OptionButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ string[] parts = tag.Split('_');
+ if (parts.Length < 2) return;
+
+ string group = parts[0];
+ string value = parts[1];
+
+ // 清除同组其他按钮的选中状态
+ var parent = border.Parent as Panel;
+ if (parent != null)
+ {
+ foreach (var child in parent.Children)
+ {
+ if (child is Border childBorder && childBorder != border)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ // 设置当前按钮为选中状态
+ border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ var currentTextBlock = border.Child as TextBlock;
+ if (currentTextBlock != null)
+ {
+ currentTextBlock.FontWeight = FontWeights.Bold;
+ }
+
+ switch (group)
+ {
+ case "PalmEraserSensitivity":
+ int sensitivity;
+ switch (value)
+ {
+ case "Low":
+ sensitivity = 0;
+ break;
+ case "Medium":
+ sensitivity = 1;
+ break;
+ case "High":
+ sensitivity = 2;
+ break;
+ default:
+ sensitivity = 0;
+ break;
+ }
+ // 调用 MainWindow 中的方法(通过设置 ComboBox 的 SelectedIndex)
+ var mainWindow = Application.Current.MainWindow as MainWindow;
+ if (mainWindow != null)
+ {
+ var comboBox = mainWindow.FindName("ComboBoxPalmEraserSensitivity") as System.Windows.Controls.ComboBox;
+ if (comboBox != null && comboBox.Items.Count > sensitivity)
+ {
+ comboBox.SelectedIndex = sensitivity;
+ // 触发 SelectionChanged 事件
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxPalmEraserSensitivity", comboBox.Items[sensitivity]);
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ if (MainWindow.Settings.Canvas != null)
+ {
+ MainWindow.Settings.Canvas.PalmEraserSensitivity = sensitivity;
+ }
+ }, "ComboBoxPalmEraserSensitivity");
+ }
+ }
+ break;
+ }
+ }
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"GesturesPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/InkRecognitionPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/InkRecognitionPanel.xaml.cs
index ade1a9b5..9ec8aa82 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/InkRecognitionPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/InkRecognitionPanel.xaml.cs
@@ -29,6 +29,21 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"InkRecognitionPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml
index 98b519e6..09c14af5 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml
@@ -35,7 +35,7 @@
-
+
@@ -49,7 +49,7 @@
-
+
@@ -63,7 +63,7 @@
-
+
@@ -77,7 +77,7 @@
-
+
@@ -92,13 +92,13 @@
-
+
-
+
-
+
@@ -115,7 +115,7 @@
-
+
@@ -126,7 +126,7 @@
-
+
@@ -142,7 +142,7 @@
-
+
@@ -156,7 +156,7 @@
-
+
@@ -171,7 +171,7 @@
-
+
@@ -182,7 +182,7 @@
-
+
@@ -201,7 +201,7 @@
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml.cs
index eca7d4c4..64cdb4bc 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/LuckyRandomPanel.xaml.cs
@@ -1,6 +1,12 @@
+using Ink_Canvas;
+using iNKORE.UI.WPF.Helpers;
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Media;
+using Application = System.Windows.Application;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -9,9 +15,41 @@ namespace Ink_Canvas.Windows.SettingsViews
///
public partial class LuckyRandomPanel : UserControl
{
+ private bool _isLoaded = false;
+
public LuckyRandomPanel()
{
InitializeComponent();
+ Loaded += LuckyRandomPanel_Loaded;
+ }
+
+ private void LuckyRandomPanel_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ // 添加触摸支持
+ EnableTouchSupport();
+ // 应用主题
+ ApplyTheme();
+ _isLoaded = true;
+ }
+
+ ///
+ /// 为面板中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupport()
+ {
+ try
+ {
+ // 延迟执行,确保所有控件都已加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ MainWindowSettingsHelper.EnableTouchSupportForControls(this);
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"LuckyRandomPanel 启用触摸支持时出错: {ex.Message}");
+ }
}
public event EventHandler IsTopBarNeedShadowEffect;
@@ -29,6 +67,379 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 加载设置到UI
+ ///
+ public void LoadSettings()
+ {
+ if (MainWindow.Settings == null || MainWindow.Settings.RandSettings == null) return;
+
+ _isLoaded = false;
+
+ try
+ {
+ var randSettings = MainWindow.Settings.RandSettings;
+
+ // 显示修改随机点名名单的按钮
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchDisplayRandWindowNamesInputBtn"), randSettings.DisplayRandWindowNamesInputBtn);
+
+ // 启用随机抽和单次抽按钮
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchShowRandomAndSingleDraw"), randSettings.ShowRandomAndSingleDraw);
+
+ // 启用快抽悬浮按钮
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableQuickDraw"), randSettings.EnableQuickDraw);
+
+ // 直接调用外部点名
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchExternalCaller"), randSettings.DirectCallCiRand);
+
+ // 点名类型
+ SetOptionButtonState("ExternalCallerType", randSettings.ExternalCallerType);
+
+ // 单次抽人窗口关闭延迟
+ if (RandWindowOnceCloseLatencySlider != null)
+ {
+ RandWindowOnceCloseLatencySlider.Value = randSettings.RandWindowOnceCloseLatency;
+ if (RandWindowOnceCloseLatencyText != null)
+ {
+ RandWindowOnceCloseLatencyText.Text = $"{randSettings.RandWindowOnceCloseLatency:F1}s";
+ }
+ }
+
+ // 单次随机点名人数上限
+ if (RandWindowOnceMaxStudentsSlider != null)
+ {
+ RandWindowOnceMaxStudentsSlider.Value = randSettings.RandWindowOnceMaxStudents;
+ if (RandWindowOnceMaxStudentsText != null)
+ {
+ RandWindowOnceMaxStudentsText.Text = randSettings.RandWindowOnceMaxStudents.ToString();
+ }
+ }
+
+ // 启用新点名UI
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchUseNewRollCallUI"), randSettings.UseNewRollCallUI);
+
+ // 启用机器学习避免重复
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableMLAvoidance"), randSettings.EnableMLAvoidance);
+
+ // 避免重复历史记录数量
+ if (MLAvoidanceHistorySlider != null)
+ {
+ MLAvoidanceHistorySlider.Value = randSettings.MLAvoidanceHistoryCount;
+ if (MLAvoidanceHistoryText != null)
+ {
+ MLAvoidanceHistoryText.Text = randSettings.MLAvoidanceHistoryCount.ToString();
+ }
+ }
+
+ // 避免重复权重
+ if (MLAvoidanceWeightSlider != null)
+ {
+ MLAvoidanceWeightSlider.Value = randSettings.MLAvoidanceWeight;
+ if (MLAvoidanceWeightText != null)
+ {
+ MLAvoidanceWeightText.Text = $"{(randSettings.MLAvoidanceWeight * 100):F0}%";
+ }
+ }
+
+ // 背景选择
+ SetOptionButtonState("PickNameBackground", randSettings.SelectedBackgroundIndex);
+ }
+ catch (Exception ex)
+ {
+ 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));
+ var innerBorder = toggleSwitch.Child as Border;
+ if (innerBorder != null)
+ {
+ innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
+ }
+ }
+
+ ///
+ /// 设置选项按钮状态
+ ///
+ private void SetOptionButtonState(string group, int selectedIndex)
+ {
+ var buttons = new Dictionary
+ {
+ { "ExternalCallerType", new[] { "ClassIsland", "SecRandom", "NamePicker" } },
+ { "PickNameBackground", new[] { "Default" } }
+ };
+
+ if (!buttons.ContainsKey(group)) return;
+
+ string[] buttonNames = buttons[group];
+
+ for (int i = 0; i < buttonNames.Length; i++)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ ///
+ /// ToggleSwitch点击事件处理
+ ///
+ private void ToggleSwitch_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ bool isOn = border.Background.ToString() == "#FF3584E4";
+ bool newState = !isOn;
+ SetToggleSwitchState(border, newState);
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ var randSettings = MainWindow.Settings.RandSettings;
+ if (randSettings == null) return;
+
+ switch (tag)
+ {
+ case "DisplayRandWindowNamesInputBtn":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchDisplayRandWindowNamesInputBtn", newState);
+ break;
+
+ case "ShowRandomAndSingleDraw":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchShowRandomAndSingleDraw", newState);
+ break;
+
+ case "EnableQuickDraw":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableQuickDraw", newState);
+ break;
+
+ case "ExternalCaller":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchExternalCaller", newState);
+ break;
+
+ case "UseNewRollCallUI":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchUseNewRollCallUI", newState);
+ break;
+
+ case "EnableMLAvoidance":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableMLAvoidance", newState);
+ break;
+ }
+ }
+
+ ///
+ /// 选项按钮点击事件处理
+ ///
+ private void OptionButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ string[] parts = tag.Split('_');
+ if (parts.Length < 2) return;
+
+ string group = parts[0];
+ string value = parts[1];
+
+ // 清除同组其他按钮的选中状态
+ var parent = border.Parent as Panel;
+ if (parent != null)
+ {
+ foreach (var child in parent.Children)
+ {
+ if (child is Border childBorder && childBorder != border)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ // 设置当前按钮为选中状态
+ border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ var currentTextBlock = border.Child as TextBlock;
+ if (currentTextBlock != null)
+ {
+ currentTextBlock.FontWeight = FontWeights.Bold;
+ }
+
+ var randSettings = MainWindow.Settings.RandSettings;
+ if (randSettings == null) return;
+
+ switch (group)
+ {
+ case "ExternalCallerType":
+ int callerType;
+ switch (value)
+ {
+ case "ClassIsland":
+ callerType = 0;
+ break;
+ case "SecRandom":
+ callerType = 1;
+ break;
+ case "NamePicker":
+ callerType = 2;
+ break;
+ default:
+ callerType = 0;
+ break;
+ }
+ // 调用 MainWindow 中的方法
+ var mainWindow = Application.Current.MainWindow as MainWindow;
+ if (mainWindow != null)
+ {
+ var comboBox = mainWindow.FindName("ComboBoxExternalCallerType") as System.Windows.Controls.ComboBox;
+ if (comboBox != null && comboBox.Items.Count > callerType)
+ {
+ comboBox.SelectedIndex = callerType;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxExternalCallerType", comboBox.Items[callerType]);
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ randSettings.ExternalCallerType = callerType;
+ }, "ComboBoxExternalCallerType");
+ }
+ }
+ break;
+
+ case "PickNameBackground":
+ // 背景选择逻辑 - 这个设置可能没有对应的方法,直接更新
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ randSettings.SelectedBackgroundIndex = 0; // 默认背景
+ }, "PickNameBackground");
+ break;
+ }
+ }
+
+ ///
+ /// Slider值变化事件处理
+ ///
+ private void RandWindowOnceCloseLatencySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (RandWindowOnceCloseLatencySlider != null && RandWindowOnceCloseLatencyText != null)
+ {
+ double value = RandWindowOnceCloseLatencySlider.Value;
+ RandWindowOnceCloseLatencyText.Text = $"{value:F1}s";
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("RandWindowOnceCloseLatencySlider", value);
+ }
+ }
+
+ private void RandWindowOnceMaxStudentsSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (RandWindowOnceMaxStudentsSlider != null && RandWindowOnceMaxStudentsText != null)
+ {
+ double value = RandWindowOnceMaxStudentsSlider.Value;
+ RandWindowOnceMaxStudentsText.Text = ((int)value).ToString();
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("RandWindowOnceMaxStudentsSlider", value);
+ }
+ }
+
+ private void MLAvoidanceHistorySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (MLAvoidanceHistorySlider != null && MLAvoidanceHistoryText != null)
+ {
+ double value = MLAvoidanceHistorySlider.Value;
+ MLAvoidanceHistoryText.Text = ((int)value).ToString();
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("MLAvoidanceHistorySlider", value);
+ }
+ }
+
+ private void MLAvoidanceWeightSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (MLAvoidanceWeightSlider != null && MLAvoidanceWeightText != null)
+ {
+ double value = MLAvoidanceWeightSlider.Value;
+ MLAvoidanceWeightText.Text = $"{(value * 100):F0}%";
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("MLAvoidanceWeightSlider", value);
+ }
+ }
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"LuckyRandomPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/MainWindowSettingsHelper.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/MainWindowSettingsHelper.cs
new file mode 100644
index 00000000..a88b64f5
--- /dev/null
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/MainWindowSettingsHelper.cs
@@ -0,0 +1,719 @@
+using Ink_Canvas;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using Media = System.Windows.Media;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Media;
+
+namespace Ink_Canvas.Windows.SettingsViews
+{
+ ///
+ /// 辅助类:用于在新设置面板中调用 MainWindow 中已有的设置处理方法
+ ///
+ public static class MainWindowSettingsHelper
+ {
+ private static MainWindow GetMainWindow()
+ {
+ return Application.Current.MainWindow as MainWindow;
+ }
+
+ ///
+ /// 调用 MainWindow 中的方法
+ ///
+ public static void InvokeMainWindowMethod(string methodName, params object[] parameters)
+ {
+ try
+ {
+ var mainWindow = GetMainWindow();
+ if (mainWindow == null) return;
+
+ var method = mainWindow.GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
+ if (method != null)
+ {
+ method.Invoke(mainWindow, parameters);
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"调用 MainWindow 方法 {methodName} 失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 调用 MainWindow 中的 ToggleSwitch 事件处理方法
+ ///
+ public static void InvokeToggleSwitchToggled(string toggleSwitchName, bool isOn)
+ {
+ try
+ {
+ var mainWindow = GetMainWindow();
+ if (mainWindow == null) return;
+
+ // 获取 MainWindow 中的 ToggleSwitch 控件
+ var toggleSwitch = mainWindow.FindName(toggleSwitchName);
+ if (toggleSwitch == null)
+ {
+ // 如果找不到控件,尝试通过反射设置属性
+ var property = mainWindow.GetType().GetProperty(toggleSwitchName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
+ if (property != null && property.PropertyType.Name.Contains("ToggleSwitch"))
+ {
+ var isOnProperty = property.PropertyType.GetProperty("IsOn");
+ if (isOnProperty != null)
+ {
+ var toggleSwitchInstance = property.GetValue(mainWindow);
+ if (toggleSwitchInstance != null)
+ {
+ isOnProperty.SetValue(toggleSwitchInstance, isOn);
+ }
+ }
+ }
+ // 即使找不到控件,也尝试触发事件(可能通过反射调用)
+ var toggledMethodName = toggleSwitchName + "_Toggled";
+ InvokeMainWindowMethod(toggledMethodName, null, new RoutedEventArgs());
+
+ // 通知新设置面板同步状态
+ NotifySettingsPanelsSyncState(toggleSwitchName);
+ return;
+ }
+
+ // 设置 ToggleSwitch 的 IsOn 属性
+ var toggleSwitchType = toggleSwitch.GetType();
+ var isOnProp = toggleSwitchType.GetProperty("IsOn");
+ if (isOnProp != null)
+ {
+ isOnProp.SetValue(toggleSwitch, isOn);
+ }
+
+ // 触发 Toggled 事件
+ var toggledMethodName2 = toggleSwitchName + "_Toggled";
+ InvokeMainWindowMethod(toggledMethodName2, toggleSwitch, new RoutedEventArgs());
+
+ // 通知新设置面板同步状态
+ NotifySettingsPanelsSyncState(toggleSwitchName);
+
+ // 检查是否需要更新主题
+ NotifyThemeUpdateIfNeeded(toggleSwitchName);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"调用 ToggleSwitch {toggleSwitchName} 失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 调用 MainWindow 中的 ComboBox 事件处理方法
+ ///
+ public static void InvokeComboBoxSelectionChanged(string comboBoxName, object selectedItem)
+ {
+ try
+ {
+ var mainWindow = GetMainWindow();
+ if (mainWindow == null) return;
+
+ // 获取 MainWindow 中的 ComboBox 控件
+ var comboBox = mainWindow.FindName(comboBoxName) as System.Windows.Controls.ComboBox;
+ if (comboBox != null)
+ {
+ comboBox.SelectedItem = selectedItem;
+
+ // 触发 SelectionChanged 事件
+ var selectionChangedMethodName = comboBoxName + "_SelectionChanged";
+ InvokeMainWindowMethod(selectionChangedMethodName, comboBox, new System.Windows.Controls.SelectionChangedEventArgs(
+ System.Windows.Controls.Primitives.Selector.SelectionChangedEvent,
+ new System.Collections.IList[0],
+ new System.Collections.IList[0]));
+ }
+
+ // 通知新设置面板同步状态
+ NotifySettingsPanelsSyncState(comboBoxName);
+
+ // 检查是否需要更新主题
+ NotifyThemeUpdateIfNeeded(comboBoxName);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"调用 ComboBox {comboBoxName} 失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 调用 MainWindow 中的 Slider 事件处理方法
+ ///
+ public static void InvokeSliderValueChanged(string sliderName, double value)
+ {
+ try
+ {
+ var mainWindow = GetMainWindow();
+ if (mainWindow == null) return;
+
+ // 获取 MainWindow 中的 Slider 控件
+ var slider = mainWindow.FindName(sliderName) as System.Windows.Controls.Slider;
+ if (slider != null)
+ {
+ var oldValue = slider.Value;
+ slider.Value = value;
+
+ // 触发 ValueChanged 事件
+ var valueChangedMethodName = sliderName + "_ValueChanged";
+ InvokeMainWindowMethod(valueChangedMethodName, slider,
+ new System.Windows.RoutedPropertyChangedEventArgs(oldValue, value));
+ }
+
+ // 通知新设置面板同步状态
+ NotifySettingsPanelsSyncState(sliderName);
+
+ // 检查是否需要更新主题(某些Slider可能影响UI外观)
+ NotifyThemeUpdateIfNeeded(sliderName);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"调用 Slider {sliderName} 失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 调用 MainWindow 中的 CheckBox 事件处理方法
+ ///
+ public static void InvokeCheckBoxCheckedChanged(string checkBoxName, bool isChecked)
+ {
+ try
+ {
+ var mainWindow = GetMainWindow();
+ if (mainWindow == null) return;
+
+ // 获取 MainWindow 中的 CheckBox 控件
+ var checkBox = mainWindow.FindName(checkBoxName) as System.Windows.Controls.CheckBox;
+ if (checkBox != null)
+ {
+ checkBox.IsChecked = isChecked;
+
+ // 尝试多种可能的方法名
+ var methodNames = new[]
+ {
+ checkBoxName + "_IsCheckChanged",
+ checkBoxName + "_IsCheckChange",
+ checkBoxName + "_Checked",
+ checkBoxName + "_Unchecked"
+ };
+
+ foreach (var methodName in methodNames)
+ {
+ var method = mainWindow.GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
+ if (method != null)
+ {
+ InvokeMainWindowMethod(methodName, checkBox, new RoutedEventArgs());
+ break;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"调用 CheckBox {checkBoxName} 失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 安全地修改设置并保存,优先调用 MainWindow 中的事件处理方法
+ /// 如果找不到对应的事件处理方法,则直接修改设置并保存
+ ///
+ /// 设置修改的 Action,例如:() => MainWindow.Settings.Startup.IsAutoUpdate = true
+ /// 可选:要调用的 MainWindow 事件处理方法名(如 "ToggleSwitchIsAutoUpdate_Toggled")
+ /// 可选:控件名称,用于状态同步(如 "ToggleSwitchIsAutoUpdate")
+ /// 可选:事件处理方法的参数
+ public static void UpdateSettingSafely(Action action, string eventHandlerName = null, string controlName = null, params object[] eventHandlerParams)
+ {
+ try
+ {
+ // 如果提供了事件处理方法名,优先调用
+ if (!string.IsNullOrEmpty(eventHandlerName))
+ {
+ var mainWindow = GetMainWindow();
+ if (mainWindow != null)
+ {
+ var method = mainWindow.GetType().GetMethod(eventHandlerName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
+ if (method != null)
+ {
+ // 调用事件处理方法(它会自动保存设置并触发状态同步)
+ method.Invoke(mainWindow, eventHandlerParams);
+
+ // 如果提供了控件名称,确保状态同步
+ if (!string.IsNullOrEmpty(controlName))
+ {
+ NotifySettingsPanelsSyncState(controlName);
+ }
+ return;
+ }
+ }
+ }
+
+ // 如果没有事件处理方法或调用失败,直接修改设置并保存
+ action?.Invoke();
+ MainWindow.SaveSettingsToFile();
+
+ // 如果提供了控件名称,通知面板同步状态
+ if (!string.IsNullOrEmpty(controlName))
+ {
+ NotifySettingsPanelsSyncState(controlName);
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"更新设置失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 直接修改设置属性并保存(用于没有对应事件处理方法的设置项)
+ ///
+ /// 设置修改的 Action
+ /// 可选:控件名称,用于状态同步(如 "ToggleSwitchIsAutoUpdate")
+ public static void UpdateSettingDirectly(Action action, string controlName = null)
+ {
+ try
+ {
+ action?.Invoke();
+ MainWindow.SaveSettingsToFile();
+
+ // 如果提供了控件名称,通知面板同步状态
+ if (!string.IsNullOrEmpty(controlName))
+ {
+ NotifySettingsPanelsSyncState(controlName);
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"直接更新设置失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 调用 MainWindow 中的 TextBox 事件处理方法
+ ///
+ public static void InvokeTextBoxTextChanged(string textBoxName, string text)
+ {
+ try
+ {
+ var mainWindow = GetMainWindow();
+ if (mainWindow == null) return;
+
+ // 获取 MainWindow 中的 TextBox 控件
+ var textBox = mainWindow.FindName(textBoxName) as System.Windows.Controls.TextBox;
+ if (textBox != null)
+ {
+ textBox.Text = text;
+
+ // 触发 TextChanged 事件
+ var textChangedMethodName = textBoxName + "_TextChanged";
+ InvokeMainWindowMethod(textChangedMethodName, textBox, new System.Windows.Controls.TextChangedEventArgs(
+ System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent,
+ System.Windows.Controls.UndoAction.None));
+ }
+
+ // 通知新设置面板同步状态
+ NotifySettingsPanelsSyncState(textBoxName);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"调用 TextBox {textBoxName} 失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 通知所有新设置面板同步指定控件的状态
+ ///
+ public static void NotifySettingsPanelsSyncState(string controlName)
+ {
+ try
+ {
+ // 延迟执行,确保设置已经保存
+ Application.Current.Dispatcher.BeginInvoke(new Action(() =>
+ {
+ // 查找所有打开的设置窗口
+ foreach (Window window in Application.Current.Windows)
+ {
+ if (window.GetType().Name == "SettingsWindow")
+ {
+ // 根据控件名称确定需要同步的面板
+ var panelToSync = GetPanelForControl(controlName);
+
+ if (panelToSync != null)
+ {
+ // 获取对应的面板属性
+ var panelProp = window.GetType().GetProperty(panelToSync, BindingFlags.Public | BindingFlags.Instance);
+ if (panelProp != null)
+ {
+ var panel = panelProp.GetValue(window) as System.Windows.Controls.UserControl;
+ if (panel != null)
+ {
+ // 调用 LoadSettings 方法重新加载设置
+ var loadMethod = panel.GetType().GetMethod("LoadSettings",
+ BindingFlags.Public | BindingFlags.Instance);
+ if (loadMethod != null)
+ {
+ loadMethod.Invoke(panel, null);
+ }
+ }
+ }
+ }
+ else
+ {
+ // 如果无法确定具体面板,则同步所有面板(保守策略)
+ SyncAllPanels(window);
+ }
+ break; // 通常只有一个设置窗口
+ }
+ }
+ }), System.Windows.Threading.DispatcherPriority.Background);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"通知设置面板同步状态失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 根据控件名称获取对应的面板名称
+ ///
+ private static string GetPanelForControl(string controlName)
+ {
+ // 定义控件名称到面板名称的映射
+ var controlToPanel = new Dictionary
+ {
+ // StartupPanel
+ { "ToggleSwitchIsAutoUpdate", "StartupPanel" },
+ { "ToggleSwitchIsAutoUpdateWithSilence", "StartupPanel" },
+ { "ToggleSwitchRunAtStartup", "StartupPanel" },
+ { "ToggleSwitchFoldAtStartup", "StartupPanel" },
+ { "AutoUpdateWithSilenceStartTimeComboBox", "StartupPanel" },
+ { "AutoUpdateWithSilenceEndTimeComboBox", "StartupPanel" },
+
+ // ThemePanel
+ { "ComboBoxTheme", "ThemePanel" },
+ { "ToggleSwitchEnableSplashScreen", "ThemePanel" },
+ { "ComboBoxSplashScreenStyle", "ThemePanel" },
+ { "ToggleSwitchEnableTrayIcon", "ThemePanel" },
+ { "ComboBoxFloatingBarImg", "ThemePanel" },
+ { "ComboBoxUnFoldBtnImg", "ThemePanel" },
+ { "ComboBoxChickenSoupSource", "ThemePanel" },
+ { "ComboBoxQuickColorPaletteDisplayMode", "ThemePanel" },
+ { "ComboBoxEraserDisplayOption", "ThemePanel" },
+ { "ToggleSwitchEnableQuickPanel", "ThemePanel" },
+ { "ViewboxFloatingBarScaleTransformValueSlider", "ThemePanel" },
+ { "ViewboxFloatingBarOpacityValueSlider", "ThemePanel" },
+ { "ViewboxFloatingBarOpacityInPPTValueSlider", "ThemePanel" },
+
+ // PowerPointPanel
+ { "ToggleSwitchSupportPowerPoint", "PowerPointPanel" },
+ { "ToggleSwitchShowPPTButton", "PowerPointPanel" },
+ { "ToggleSwitchEnablePPTButtonPageClickable", "PowerPointPanel" },
+ { "ToggleSwitchShowCanvasAtNewSlideShow", "PowerPointPanel" },
+ { "PPTButtonLeftPositionValueSlider", "PowerPointPanel" },
+ { "PPTButtonRightPositionValueSlider", "PowerPointPanel" },
+
+ // GesturesPanel
+ { "ToggleSwitchEnableTwoFingerRotationOnSelection", "GesturesPanel" },
+ { "ToggleSwitchEnablePalmEraser", "GesturesPanel" },
+ { "ComboBoxPalmEraserSensitivity", "GesturesPanel" },
+
+ // CanvasAndInkPanel
+ { "ToggleSwitchShowCursor", "CanvasAndInkPanel" },
+ { "ToggleSwitchDisablePressure", "CanvasAndInkPanel" },
+ { "ToggleSwitchEnablePressureTouchMode", "CanvasAndInkPanel" },
+ { "ComboBoxEraserSize", "CanvasAndInkPanel" },
+ { "ComboBoxHyperbolaAsymptoteOption", "CanvasAndInkPanel" },
+ { "ComboBoxAutoSaveStrokesInterval", "CanvasAndInkPanel" },
+
+ // SnapshotPanel
+ { "AutoSavedStrokesLocation", "SnapshotPanel" },
+ { "ComboBoxAutoDelSavedFilesDaysThreshold", "SnapshotPanel" },
+ { "ToggleSwitchAutoDelSavedFiles", "SnapshotPanel" },
+
+ // AdvancedPanel
+ { "ComboBoxAutoBackupInterval", "AdvancedPanel" },
+ { "ToggleSwitchIsQuadIR", "AdvancedPanel" },
+ { "ToggleSwitchIsLogEnabled", "AdvancedPanel" },
+ { "ToggleSwitchIsSaveLogByDate", "AdvancedPanel" },
+ { "ToggleSwitchIsSecondConfimeWhenShutdownApp", "AdvancedPanel" },
+ { "ToggleSwitchIsEnableFullScreenHelper", "AdvancedPanel" },
+ { "ToggleSwitchIsEnableAvoidFullScreenHelper", "AdvancedPanel" },
+ { "ToggleSwitchIsEnableEdgeGestureUtil", "AdvancedPanel" },
+ { "ToggleSwitchIsEnableForceFullScreen", "AdvancedPanel" },
+ { "ToggleSwitchIsEnableDPIChangeDetection", "AdvancedPanel" },
+ { "ToggleSwitchIsEnableResolutionChangeDetection", "AdvancedPanel" },
+ { "ToggleSwitchIsAutoBackupBeforeUpdate", "AdvancedPanel" },
+ { "ToggleSwitchIsAutoBackupEnabled", "AdvancedPanel" },
+
+ // LuckyRandomPanel
+ { "ToggleSwitchDisplayRandWindowNamesInputBtn", "LuckyRandomPanel" },
+ { "ToggleSwitchShowRandomAndSingleDraw", "LuckyRandomPanel" },
+ { "ToggleSwitchEnableQuickDraw", "LuckyRandomPanel" },
+ { "ToggleSwitchExternalCaller", "LuckyRandomPanel" },
+ { "ComboBoxExternalCallerType", "LuckyRandomPanel" },
+ { "RandWindowOnceCloseLatencySlider", "LuckyRandomPanel" },
+ { "RandWindowOnceMaxStudentsSlider", "LuckyRandomPanel" },
+ };
+
+ // 查找匹配的面板
+ foreach (var kvp in controlToPanel)
+ {
+ if (controlName.Contains(kvp.Key) || kvp.Key.Contains(controlName))
+ {
+ return kvp.Value;
+ }
+ }
+
+ return null;
+ }
+
+ ///
+ /// 同步所有面板的状态(保守策略)
+ ///
+ private static void SyncAllPanels(Window settingsWindow)
+ {
+ try
+ {
+ // 获取所有面板属性
+ var panelProperties = settingsWindow.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
+ .Where(p => p.PropertyType.Name.EndsWith("Panel") &&
+ p.PropertyType.IsSubclassOf(typeof(System.Windows.Controls.UserControl)));
+
+ foreach (var panelProp in panelProperties)
+ {
+ try
+ {
+ var panel = panelProp.GetValue(settingsWindow) as System.Windows.Controls.UserControl;
+ if (panel != null)
+ {
+ // 调用 LoadSettings 方法
+ var loadMethod = panel.GetType().GetMethod("LoadSettings",
+ BindingFlags.Public | BindingFlags.Instance);
+ if (loadMethod != null)
+ {
+ loadMethod.Invoke(panel, null);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"同步面板 {panelProp.Name} 状态失败: {ex.Message}");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"同步所有面板状态失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 检查并通知设置窗口更新主题(如果设置变化可能影响主题)
+ ///
+ /// 控件名称,用于判断是否是主题相关的设置
+ public static void NotifyThemeUpdateIfNeeded(string controlName)
+ {
+ try
+ {
+ if (string.IsNullOrEmpty(controlName)) return;
+
+ // 定义可能影响主题的控件名称列表(扩展版)
+ var themeRelatedControls = new[]
+ {
+ "ComboBoxTheme", // 主题选择
+ "ToggleSwitchEnableTrayIcon", // 托盘图标(可能影响图标颜色)
+ "ComboBoxFloatingBarImg", // 浮动栏图标
+ "ComboBoxUnFoldBtnImg", // 展开按钮图标
+ "ComboBoxSplashScreenStyle", // 启动画面样式
+ "ToggleSwitchEnableSplashScreen", // 启动画面开关
+ "ViewboxFloatingBarScaleTransformValueSlider", // 浮动栏缩放(可能影响UI)
+ "ViewboxFloatingBarOpacityValueSlider", // 浮动栏透明度
+ "ViewboxFloatingBarOpacityInPPTValueSlider", // PPT中浮动栏透明度
+ "UnFoldBtnImg", // 展开按钮图标(选项按钮)
+ "FloatingBarImg", // 浮动栏图标(选项按钮)
+ "Theme" // 主题(选项按钮)
+ };
+
+ // 检查是否是主题相关的设置(使用更灵活的匹配)
+ bool isThemeRelated = false;
+ string controlNameLower = controlName.ToLower();
+
+ foreach (var themeControl in themeRelatedControls)
+ {
+ string themeControlLower = themeControl.ToLower();
+ // 检查是否包含或匹配
+ if (controlNameLower.Contains(themeControlLower) ||
+ themeControlLower.Contains(controlNameLower) ||
+ controlNameLower == themeControlLower)
+ {
+ isThemeRelated = true;
+ break;
+ }
+ }
+
+ if (isThemeRelated)
+ {
+ // 延迟通知,确保设置已保存
+ Application.Current.Dispatcher.BeginInvoke(new Action(() =>
+ {
+ // 通知设置窗口更新主题
+ NotifySettingsWindowThemeUpdate();
+ }), System.Windows.Threading.DispatcherPriority.Background);
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"通知主题更新失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 通知设置窗口更新所有面板的主题
+ ///
+ private static void NotifySettingsWindowThemeUpdate()
+ {
+ try
+ {
+ // 查找所有打开的设置窗口
+ foreach (Window window in Application.Current.Windows)
+ {
+ // 使用类型名称匹配,因为 SettingsWindow 在不同的命名空间中
+ if (window.GetType().Name == "SettingsWindow")
+ {
+ // 使用反射调用 ApplyThemeToAllPanels 方法
+ var method = window.GetType().GetMethod("ApplyThemeToAllPanels",
+ BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
+ if (method != null)
+ {
+ method.Invoke(window, null);
+ }
+
+ // 同时调用 ApplyTheme 方法更新窗口本身
+ var applyThemeMethod = window.GetType().GetMethod("ApplyTheme",
+ BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
+ if (applyThemeMethod != null)
+ {
+ applyThemeMethod.Invoke(window, null);
+ }
+
+ break; // 通常只有一个设置窗口
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"通知设置窗口主题更新失败: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 强制更新所有设置面板的主题(公共方法,可在外部调用)
+ ///
+ public static void ForceUpdateAllPanelsTheme()
+ {
+ NotifySettingsWindowThemeUpdate();
+ }
+
+ ///
+ /// 调用 MainWindow 中的 ComboBox 事件处理方法(增强版,支持主题更新通知)
+ ///
+ public static void InvokeComboBoxSelectionChangedWithThemeCheck(string comboBoxName, object selectedItem)
+ {
+ InvokeComboBoxSelectionChanged(comboBoxName, selectedItem);
+ NotifyThemeUpdateIfNeeded(comboBoxName);
+ }
+
+ ///
+ /// 调用 MainWindow 中的 ToggleSwitch 事件处理方法(增强版,支持主题更新通知)
+ ///
+ public static void InvokeToggleSwitchToggledWithThemeCheck(string toggleSwitchName, bool isOn)
+ {
+ InvokeToggleSwitchToggled(toggleSwitchName, isOn);
+ NotifyThemeUpdateIfNeeded(toggleSwitchName);
+ }
+
+ ///
+ /// 为控件树中的所有交互控件启用触摸支持(公共方法,可在外部调用)
+ ///
+ /// 父控件
+ public static void EnableTouchSupportForControls(DependencyObject parent)
+ {
+ if (parent == null) return;
+
+ for (int i = 0; i < Media.VisualTreeHelper.GetChildrenCount(parent); i++)
+ {
+ var child = Media.VisualTreeHelper.GetChild(parent, i);
+
+ // 为 Border 控件(ToggleSwitch、选项按钮等)启用触摸支持
+ if (child is Border border)
+ {
+ // 检查是否是交互控件(有 Tag 或 Cursor 为 Hand)
+ if (border.Tag != null || border.Cursor == Cursors.Hand)
+ {
+ border.IsManipulationEnabled = true;
+
+ // 添加触摸事件支持,将触摸事件转换为鼠标事件
+ border.TouchDown += (s, e) =>
+ {
+ var touchPoint = e.GetTouchPoint(border);
+ var mouseEvent = new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left)
+ {
+ RoutedEvent = UIElement.MouseLeftButtonDownEvent,
+ Source = border
+ };
+ border.RaiseEvent(mouseEvent);
+ border.CaptureTouch(e.TouchDevice);
+ e.Handled = true;
+ };
+
+ // 添加触摸释放事件
+ border.TouchUp += (s, e) =>
+ {
+ border.ReleaseTouchCapture(e.TouchDevice);
+ e.Handled = true;
+ };
+ }
+ }
+ // 为 Button 控件启用触摸支持
+ else if (child is Button button)
+ {
+ button.IsManipulationEnabled = true;
+ }
+ // 为 ComboBox 启用触摸支持
+ else if (child is ComboBox comboBox)
+ {
+ comboBox.IsManipulationEnabled = true;
+ }
+ // 为 Slider 启用触摸支持
+ else if (child is Slider slider)
+ {
+ slider.IsManipulationEnabled = true;
+ }
+ // 为 TextBox 启用触摸支持
+ else if (child is TextBox textBox)
+ {
+ textBox.IsManipulationEnabled = true;
+ }
+ // 为 CheckBox 启用触摸支持
+ else if (child is CheckBox checkBox)
+ {
+ checkBox.IsManipulationEnabled = true;
+ }
+ // 为 RadioButton 启用触摸支持
+ else if (child is RadioButton radioButton)
+ {
+ radioButton.IsManipulationEnabled = true;
+ }
+
+ // 递归处理子元素
+ EnableTouchSupportForControls(child);
+ }
+ }
+ }
+}
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml
index 46b7278b..a530fc2e 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml
@@ -37,7 +37,7 @@
-
+
@@ -51,7 +51,7 @@
-
+
@@ -65,7 +65,7 @@
-
+
@@ -79,7 +79,7 @@
-
+
@@ -160,7 +160,7 @@
-
+
@@ -170,114 +170,178 @@
-
-
-
-
+
+
+
+
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
@@ -290,7 +354,7 @@
-
+
@@ -308,7 +372,7 @@
-
+
@@ -326,7 +390,7 @@
-
+
@@ -346,7 +410,7 @@
-
+
@@ -378,7 +442,7 @@
-
+
@@ -392,7 +456,7 @@
-
+
@@ -406,7 +470,7 @@
-
+
@@ -425,7 +489,7 @@
-
+
@@ -440,13 +504,13 @@
-
+
-
+
-
+
@@ -462,7 +526,7 @@
-
+
@@ -476,7 +540,7 @@
-
+
@@ -490,7 +554,7 @@
-
+
@@ -504,7 +568,7 @@
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml.cs
index 0deccedd..be535ad7 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/PowerPointPanel.xaml.cs
@@ -1,6 +1,11 @@
+using Ink_Canvas;
+using iNKORE.UI.WPF.Helpers;
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Media;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -9,9 +14,41 @@ namespace Ink_Canvas.Windows.SettingsViews
///
public partial class PowerPointPanel : UserControl
{
+ private bool _isLoaded = false;
+
public PowerPointPanel()
{
InitializeComponent();
+ Loaded += PowerPointPanel_Loaded;
+ }
+
+ private void PowerPointPanel_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ // 添加触摸支持
+ EnableTouchSupport();
+ // 应用主题
+ ApplyTheme();
+ _isLoaded = true;
+ }
+
+ ///
+ /// 为面板中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupport()
+ {
+ try
+ {
+ // 延迟执行,确保所有控件都已加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ MainWindowSettingsHelper.EnableTouchSupportForControls(this);
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"PowerPointPanel 启用触摸支持时出错: {ex.Message}");
+ }
}
public event EventHandler IsTopBarNeedShadowEffect;
@@ -29,6 +66,583 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 加载设置到UI
+ ///
+ public void LoadSettings()
+ {
+ if (MainWindow.Settings == null || MainWindow.Settings.PowerPointSettings == null) return;
+
+ _isLoaded = false;
+
+ try
+ {
+ var pptSettings = MainWindow.Settings.PowerPointSettings;
+
+ // Microsoft PowerPoint 支持
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchSupportPowerPoint"), pptSettings.PowerPointSupport);
+
+ // PowerPoint 联动增强
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchPowerPointEnhancement"), pptSettings.EnablePowerPointEnhancement);
+
+ // WPS 支持
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchSupportWPS"), pptSettings.IsSupportWPS);
+
+ // WPP进程查杀
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableWppProcessKill"), pptSettings.EnableWppProcessKill);
+
+ // 在 PPT 模式下显示翻页按钮
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchShowPPTButton"), pptSettings.ShowPPTButton);
+ if (PPTButtonSettingsPanel != null)
+ {
+ PPTButtonSettingsPanel.Visibility = pptSettings.ShowPPTButton ? Visibility.Visible : Visibility.Collapsed;
+ }
+
+ // PPT按钮显示选项
+ var dops = pptSettings.PPTButtonsDisplayOption.ToString();
+ var dopsc = dops.ToCharArray();
+ if (dopsc.Length >= 4)
+ {
+ if (CheckboxEnableLBPPTButton != null) CheckboxEnableLBPPTButton.IsChecked = dopsc[0] == '2';
+ if (CheckboxEnableRBPPTButton != null) CheckboxEnableRBPPTButton.IsChecked = dopsc[1] == '2';
+ if (CheckboxEnableLSPPTButton != null) CheckboxEnableLSPPTButton.IsChecked = dopsc[2] == '2';
+ if (CheckboxEnableRSPPTButton != null) CheckboxEnableRSPPTButton.IsChecked = dopsc[3] == '2';
+ }
+
+ // 按钮位置
+ if (PPTButtonLeftPositionValueSlider != null)
+ {
+ PPTButtonLeftPositionValueSlider.Value = pptSettings.PPTLSButtonPosition;
+ if (PPTButtonLeftPositionValueText != null)
+ {
+ PPTButtonLeftPositionValueText.Text = pptSettings.PPTLSButtonPosition.ToString();
+ }
+ }
+ if (PPTButtonRightPositionValueSlider != null)
+ {
+ PPTButtonRightPositionValueSlider.Value = pptSettings.PPTRSButtonPosition;
+ if (PPTButtonRightPositionValueText != null)
+ {
+ PPTButtonRightPositionValueText.Text = pptSettings.PPTRSButtonPosition.ToString();
+ }
+ }
+ if (PPTButtonLBPositionValueSlider != null)
+ {
+ PPTButtonLBPositionValueSlider.Value = pptSettings.PPTLBButtonPosition;
+ if (PPTButtonLBPositionValueText != null)
+ {
+ PPTButtonLBPositionValueText.Text = pptSettings.PPTLBButtonPosition.ToString();
+ }
+ }
+ if (PPTButtonRBPositionValueSlider != null)
+ {
+ PPTButtonRBPositionValueSlider.Value = pptSettings.PPTRBButtonPosition;
+ if (PPTButtonRBPositionValueText != null)
+ {
+ PPTButtonRBPositionValueText.Text = pptSettings.PPTRBButtonPosition.ToString();
+ }
+ }
+
+ // 两侧按钮选项
+ var sops = pptSettings.PPTSButtonsOption.ToString();
+ var sopsc = sops.ToCharArray();
+ if (sopsc.Length >= 3)
+ {
+ if (CheckboxSPPTDisplayPage != null) CheckboxSPPTDisplayPage.IsChecked = sopsc[0] == '2';
+ if (CheckboxSPPTHalfOpacity != null) CheckboxSPPTHalfOpacity.IsChecked = sopsc[1] == '2';
+ if (CheckboxSPPTBlackBackground != null) CheckboxSPPTBlackBackground.IsChecked = sopsc[2] == '2';
+ }
+
+ // 左下右下按钮选项
+ var bops = pptSettings.PPTBButtonsOption.ToString();
+ var bopsc = bops.ToCharArray();
+ if (bopsc.Length >= 3)
+ {
+ if (CheckboxBPPTDisplayPage != null) CheckboxBPPTDisplayPage.IsChecked = bopsc[0] == '2';
+ if (CheckboxBPPTHalfOpacity != null) CheckboxBPPTHalfOpacity.IsChecked = bopsc[1] == '2';
+ if (CheckboxBPPTBlackBackground != null) CheckboxBPPTBlackBackground.IsChecked = bopsc[2] == '2';
+ }
+
+ // 按钮透明度
+ if (PPTLSButtonOpacityValueSlider != null)
+ {
+ PPTLSButtonOpacityValueSlider.Value = pptSettings.PPTLSButtonOpacity > 0 ? pptSettings.PPTLSButtonOpacity : 0.5;
+ if (PPTLSButtonOpacityValueText != null)
+ {
+ PPTLSButtonOpacityValueText.Text = PPTLSButtonOpacityValueSlider.Value.ToString("F1");
+ }
+ }
+ if (PPTRSButtonOpacityValueSlider != null)
+ {
+ PPTRSButtonOpacityValueSlider.Value = pptSettings.PPTRSButtonOpacity > 0 ? pptSettings.PPTRSButtonOpacity : 0.5;
+ if (PPTRSButtonOpacityValueText != null)
+ {
+ PPTRSButtonOpacityValueText.Text = PPTRSButtonOpacityValueSlider.Value.ToString("F1");
+ }
+ }
+ if (PPTLBButtonOpacityValueSlider != null)
+ {
+ PPTLBButtonOpacityValueSlider.Value = pptSettings.PPTLBButtonOpacity > 0 ? pptSettings.PPTLBButtonOpacity : 0.5;
+ if (PPTLBButtonOpacityValueText != null)
+ {
+ PPTLBButtonOpacityValueText.Text = PPTLBButtonOpacityValueSlider.Value.ToString("F1");
+ }
+ }
+ if (PPTRBButtonOpacityValueSlider != null)
+ {
+ PPTRBButtonOpacityValueSlider.Value = pptSettings.PPTRBButtonOpacity > 0 ? pptSettings.PPTRBButtonOpacity : 0.5;
+ if (PPTRBButtonOpacityValueText != null)
+ {
+ PPTRBButtonOpacityValueText.Text = PPTRBButtonOpacityValueSlider.Value.ToString("F1");
+ }
+ }
+
+ // PPT 页码按钮可点击
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnablePPTButtonPageClickable"), pptSettings.EnablePPTButtonPageClickable);
+
+ // PPT 翻页按钮长按翻页
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnablePPTButtonLongPressPageTurn"), pptSettings.EnablePPTButtonLongPressPageTurn);
+
+ // 点击翻页时跳过转场动画
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchSkipAnimationsWhenGoNext"), pptSettings.SkipAnimationsWhenGoNext);
+
+ // 进入 PPT 放映时自动进入批注模式
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchShowCanvasAtNewSlideShow"), pptSettings.IsShowCanvasAtNewSlideShow);
+
+ // 允许幻灯片模式下的双指手势
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableTwoFingerGestureInPresentationMode"), pptSettings.IsEnableTwoFingerGestureInPresentationMode);
+
+ // 允许使用手指手势进行幻灯片翻页
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableFingerGestureSlideShowControl"), pptSettings.IsEnableFingerGestureSlideShowControl);
+
+ // PPT 放映模式显示手势按钮
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchShowGestureButtonInSlideShow"), pptSettings.ShowGestureButtonInSlideShow);
+
+ // PPT时间显示胶囊
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnablePPTTimeCapsule"), pptSettings.EnablePPTTimeCapsule);
+
+ // 时间胶囊位置
+ SetOptionButtonState("PPTTimeCapsulePosition", pptSettings.PPTTimeCapsulePosition);
+
+ // 记忆并提示上次播放位置
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchNotifyPreviousPage"), pptSettings.IsNotifyPreviousPage);
+
+ // 进入放映时回到首页
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAlwaysGoToFirstPageOnReenter"), pptSettings.IsAlwaysGoToFirstPageOnReenter);
+
+ // 提示隐藏幻灯片
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchNotifyHiddenPage"), pptSettings.IsNotifyHiddenPage);
+
+ // 提示是否已启用自动播放
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchNotifyAutoPlayPresentation"), pptSettings.IsNotifyAutoPlayPresentation);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"加载PowerPoint设置时出错: {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));
+ var innerBorder = toggleSwitch.Child as Border;
+ if (innerBorder != null)
+ {
+ innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
+ }
+ }
+
+ ///
+ /// 设置选项按钮状态
+ ///
+ private void SetOptionButtonState(string group, int selectedIndex)
+ {
+ var buttons = new Dictionary
+ {
+ { "PPTTimeCapsulePosition", new[] { "TopLeft", "TopRight", "TopCenter" } }
+ };
+
+ if (!buttons.ContainsKey(group)) return;
+
+ string[] buttonNames = buttons[group];
+
+ for (int i = 0; i < buttonNames.Length; i++)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ ///
+ /// ToggleSwitch点击事件处理
+ ///
+ private void ToggleSwitch_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ bool isOn = border.Background.ToString() == "#FF3584E4";
+ bool newState = !isOn;
+ SetToggleSwitchState(border, newState);
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ var pptSettings = MainWindow.Settings.PowerPointSettings;
+ if (pptSettings == null) return;
+
+ switch (tag)
+ {
+ case "SupportPowerPoint":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchSupportPowerPoint", newState);
+ break;
+
+ case "PowerPointEnhancement":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchPowerPointEnhancement", newState);
+ break;
+
+ case "SupportWPS":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchSupportWPS", newState);
+ break;
+
+ case "EnableWppProcessKill":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableWppProcessKill", newState);
+ break;
+
+ case "ShowPPTButton":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchShowPPTButton", newState);
+ // 更新UI状态
+ if (PPTButtonSettingsPanel != null)
+ {
+ PPTButtonSettingsPanel.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
+ }
+ break;
+
+ case "EnablePPTButtonPageClickable":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnablePPTButtonPageClickable", newState);
+ break;
+
+ case "EnablePPTButtonLongPressPageTurn":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnablePPTButtonLongPressPageTurn", newState);
+ break;
+
+ case "SkipAnimationsWhenGoNext":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchSkipAnimationsWhenGoNext", newState);
+ break;
+
+ case "ShowCanvasAtNewSlideShow":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchShowCanvasAtNewSlideShow", newState);
+ break;
+
+ case "EnableTwoFingerGestureInPresentationMode":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableTwoFingerGestureInPresentationMode", newState);
+ break;
+
+ case "EnableFingerGestureSlideShowControl":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableFingerGestureSlideShowControl", newState);
+ break;
+
+ case "ShowGestureButtonInSlideShow":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchShowGestureButtonInSlideShow", newState);
+ break;
+
+ case "EnablePPTTimeCapsule":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnablePPTTimeCapsule", newState);
+ break;
+
+ case "NotifyPreviousPage":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchNotifyPreviousPage", newState);
+ break;
+
+ case "AlwaysGoToFirstPageOnReenter":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAlwaysGoToFirstPageOnReenter", newState);
+ break;
+
+ case "NotifyHiddenPage":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchNotifyHiddenPage", newState);
+ break;
+
+ case "NotifyAutoPlayPresentation":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchNotifyAutoPlayPresentation", newState);
+ break;
+ }
+ }
+
+ ///
+ /// 选项按钮点击事件处理
+ ///
+ private void OptionButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ string[] parts = tag.Split('_');
+ if (parts.Length < 2) return;
+
+ string group = parts[0];
+ string value = parts[1];
+
+ // 清除同组其他按钮的选中状态
+ var parent = border.Parent as Panel;
+ if (parent != null)
+ {
+ foreach (var child in parent.Children)
+ {
+ if (child is Border childBorder && childBorder != border)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ // 设置当前按钮为选中状态
+ border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ var currentTextBlock = border.Child as TextBlock;
+ if (currentTextBlock != null)
+ {
+ currentTextBlock.FontWeight = FontWeights.Bold;
+ }
+
+ var pptSettings = MainWindow.Settings.PowerPointSettings;
+ if (pptSettings == null) return;
+
+ switch (group)
+ {
+ case "PPTTimeCapsulePosition":
+ int position;
+ switch (value)
+ {
+ case "TopLeft":
+ position = 0;
+ break;
+ case "TopRight":
+ position = 1;
+ break;
+ case "TopCenter":
+ position = 2;
+ break;
+ default:
+ position = 1;
+ break;
+ }
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ pptSettings.PPTTimeCapsulePosition = position;
+ }, "PPTTimeCapsulePosition");
+ break;
+ }
+ }
+
+ ///
+ /// CheckBox变化事件处理
+ ///
+ private void CheckBox_CheckedChanged(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var checkBox = sender as CheckBox;
+ if (checkBox == null) return;
+
+ string name = checkBox.Name;
+ var pptSettings = MainWindow.Settings.PowerPointSettings;
+ if (pptSettings == null) return;
+
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeCheckBoxCheckedChanged(name, checkBox.IsChecked ?? false);
+ }
+
+
+ ///
+ /// Slider值变化事件处理
+ ///
+ private void PPTButtonPositionSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var slider = sender as Slider;
+ if (slider == null) return;
+
+ string name = slider.Name;
+ double value = slider.Value;
+
+ // 更新文本显示
+ switch (name)
+ {
+ case "PPTButtonLeftPositionValueSlider":
+ if (PPTButtonLeftPositionValueText != null)
+ {
+ PPTButtonLeftPositionValueText.Text = ((int)value).ToString();
+ }
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("PPTButtonLeftPositionValueSlider", value);
+ break;
+
+ case "PPTButtonRightPositionValueSlider":
+ if (PPTButtonRightPositionValueText != null)
+ {
+ PPTButtonRightPositionValueText.Text = ((int)value).ToString();
+ }
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("PPTButtonRightPositionValueSlider", value);
+ break;
+
+ case "PPTButtonLBPositionValueSlider":
+ if (PPTButtonLBPositionValueText != null)
+ {
+ PPTButtonLBPositionValueText.Text = ((int)value).ToString();
+ }
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("PPTButtonLBPositionValueSlider", value);
+ break;
+
+ case "PPTButtonRBPositionValueSlider":
+ if (PPTButtonRBPositionValueText != null)
+ {
+ PPTButtonRBPositionValueText.Text = ((int)value).ToString();
+ }
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("PPTButtonRBPositionValueSlider", value);
+ break;
+ }
+ }
+
+ ///
+ /// 按钮透明度Slider值变化事件处理
+ ///
+ private void PPTButtonOpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var slider = sender as Slider;
+ if (slider == null) return;
+
+ string name = slider.Name;
+ double value = slider.Value;
+
+ // 更新文本显示
+ switch (name)
+ {
+ case "PPTLSButtonOpacityValueSlider":
+ if (PPTLSButtonOpacityValueText != null)
+ {
+ PPTLSButtonOpacityValueText.Text = value.ToString("F1");
+ }
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("PPTLSButtonOpacityValueSlider", value);
+ break;
+
+ case "PPTRSButtonOpacityValueSlider":
+ if (PPTRSButtonOpacityValueText != null)
+ {
+ PPTRSButtonOpacityValueText.Text = value.ToString("F1");
+ }
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("PPTRSButtonOpacityValueSlider", value);
+ break;
+
+ case "PPTLBButtonOpacityValueSlider":
+ if (PPTLBButtonOpacityValueText != null)
+ {
+ PPTLBButtonOpacityValueText.Text = value.ToString("F1");
+ }
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("PPTLBButtonOpacityValueSlider", value);
+ break;
+
+ case "PPTRBButtonOpacityValueSlider":
+ if (PPTRBButtonOpacityValueText != null)
+ {
+ PPTRBButtonOpacityValueText.Text = value.ToString("F1");
+ }
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("PPTRBButtonOpacityValueSlider", value);
+ break;
+ }
+ }
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"PowerPointPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
-
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/SearchPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/SearchPanel.xaml
index d36e7f85..073bbe38 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/SearchPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/SearchPanel.xaml
@@ -6,10 +6,10 @@
xmlns:local="clr-namespace:Ink_Canvas.Windows.SettingsViews"
mc:Ignorable="d"
d:DesignHeight="691" d:DesignWidth="910">
-
+
-
+
@@ -20,7 +20,7 @@
-
+
@@ -67,7 +67,7 @@
-
+
@@ -87,7 +87,7 @@
-
+
@@ -107,7 +107,7 @@
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/SearchPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/SearchPanel.xaml.cs
index bb551de6..89556004 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/SearchPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/SearchPanel.xaml.cs
@@ -380,6 +380,196 @@ namespace Ink_Canvas.Windows.SettingsViews
SearchTextBox.Text = text;
PerformSearch(text);
}
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ bool isDarkTheme = ThemeHelper.IsDarkTheme;
+
+ // 更新主背景
+ if (SearchPanelMainGrid != null)
+ {
+ SearchPanelMainGrid.Background = ThemeHelper.GetBackgroundPrimaryBrush();
+ }
+
+ // 更新顶部栏背景
+ if (SearchPanelTopBarBorder != null)
+ {
+ SearchPanelTopBarBorder.Background = ThemeHelper.GetBackgroundPrimaryBrush();
+ }
+
+ // 更新搜索输入框
+ if (SearchInputBorder != null)
+ {
+ SearchInputBorder.Background = ThemeHelper.GetTextBoxBackgroundBrush();
+ SearchInputBorder.BorderBrush = ThemeHelper.GetTextBoxBorderBrush();
+ }
+
+ // 更新搜索框文字颜色
+ if (SearchTextBox != null)
+ {
+ SearchTextBox.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+
+ // 更新标题文字颜色
+ if (ExactMatchTitle != null)
+ {
+ ExactMatchTitle.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+ if (FuzzyMatchTitle != null)
+ {
+ FuzzyMatchTitle.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+ if (RelatedItemsTitle != null)
+ {
+ RelatedItemsTitle.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+
+ // 更新无结果提示文字颜色
+ if (NoResultsText != null)
+ {
+ NoResultsText.Foreground = ThemeHelper.GetTextSecondaryBrush();
+ }
+
+ // 更新搜索框中的图标颜色
+ UpdateSearchIconColor(isDarkTheme);
+
+ // 使用 ThemeHelper 递归更新其他元素(如搜索结果项)
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"SearchPanel 应用主题时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 更新搜索框中的图标颜色
+ ///
+ private void UpdateSearchIconColor(bool isDarkTheme)
+ {
+ try
+ {
+ Color iconColor = isDarkTheme
+ ? Color.FromRgb(243, 243, 243) // 深色主题使用浅色图标 #F3F3F3
+ : Color.FromRgb(34, 34, 34); // 浅色主题使用深色图标 #222222
+
+ // 查找搜索输入框中的图标
+ if (SearchInputBorder != null)
+ {
+ var image = FindVisualChild(SearchInputBorder);
+ if (image != null && image.Source is DrawingImage drawingImage)
+ {
+ if (drawingImage.Drawing is DrawingGroup drawingGroup)
+ {
+ var clonedDrawing = CloneDrawingGroup(drawingGroup, iconColor);
+ image.Source = new DrawingImage { Drawing = clonedDrawing };
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"更新搜索图标颜色时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 克隆 DrawingGroup 并更新颜色
+ ///
+ private DrawingGroup CloneDrawingGroup(DrawingGroup source, Color newColor)
+ {
+ var cloned = new DrawingGroup();
+ cloned.ClipGeometry = source.ClipGeometry?.Clone();
+ cloned.Opacity = source.Opacity;
+ cloned.Transform = source.Transform?.Clone();
+
+ foreach (var drawing in source.Children)
+ {
+ if (drawing is GeometryDrawing geometryDrawing)
+ {
+ var clonedGeometry = geometryDrawing.Geometry?.Clone();
+ var clonedBrush = CloneBrush(geometryDrawing.Brush, newColor);
+ var clonedPen = geometryDrawing.Pen != null
+ ? ClonePen(geometryDrawing.Pen, newColor)
+ : null;
+
+ cloned.Children.Add(new GeometryDrawing(clonedBrush, clonedPen, clonedGeometry));
+ }
+ else if (drawing is DrawingGroup subGroup)
+ {
+ cloned.Children.Add(CloneDrawingGroup(subGroup, newColor));
+ }
+ else
+ {
+ cloned.Children.Add(drawing);
+ }
+ }
+
+ return cloned;
+ }
+
+ ///
+ /// 克隆 Brush 并更新颜色
+ ///
+ private Brush CloneBrush(Brush source, Color newColor)
+ {
+ if (source is SolidColorBrush solidBrush)
+ {
+ var originalColor = solidBrush.Color;
+ if (originalColor.R == 34 && originalColor.G == 34 && originalColor.B == 34) // #222222
+ {
+ return new SolidColorBrush(newColor) { Opacity = solidBrush.Opacity };
+ }
+ else if (originalColor.A > 0 && originalColor != Colors.Transparent &&
+ originalColor.R < 50 && originalColor.G < 50 && originalColor.B < 50) // 深色
+ {
+ return new SolidColorBrush(newColor) { Opacity = solidBrush.Opacity };
+ }
+ return new SolidColorBrush(originalColor) { Opacity = solidBrush.Opacity };
+ }
+ return source?.Clone();
+ }
+
+ ///
+ /// 克隆 Pen 并更新颜色
+ ///
+ private Pen ClonePen(Pen source, Color newColor)
+ {
+ var clonedBrush = CloneBrush(source.Brush, newColor);
+ return new Pen(clonedBrush, source.Thickness)
+ {
+ StartLineCap = source.StartLineCap,
+ EndLineCap = source.EndLineCap,
+ LineJoin = source.LineJoin,
+ MiterLimit = source.MiterLimit
+ };
+ }
+
+ ///
+ /// 在视觉树中查找指定类型的子元素
+ ///
+ private T FindVisualChild(DependencyObject parent) where T : DependencyObject
+ {
+ for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); i++)
+ {
+ var child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
+ if (child is T result)
+ {
+ return result;
+ }
+ var childOfChild = FindVisualChild(child);
+ if (childOfChild != null)
+ {
+ return childOfChild;
+ }
+ }
+ return null;
+ }
}
public class SettingItem
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/SettingsPanelBase.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/SettingsPanelBase.cs
new file mode 100644
index 00000000..6f4db549
--- /dev/null
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/SettingsPanelBase.cs
@@ -0,0 +1,273 @@
+using Ink_Canvas;
+using iNKORE.UI.WPF.Helpers;
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Media;
+
+namespace Ink_Canvas.Windows.SettingsViews
+{
+ ///
+ /// 设置面板基类,提供通用的辅助方法
+ ///
+ public abstract class SettingsPanelBase : UserControl
+ {
+ protected bool _isLoaded = false;
+
+ public SettingsPanelBase()
+ {
+ Loaded += SettingsPanelBase_Loaded;
+ }
+
+ private void SettingsPanelBase_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ // 添加触摸支持
+ EnableTouchSupport();
+ // 应用主题(如果面板有 ApplyTheme 方法)
+ try
+ {
+ var applyThemeMethod = this.GetType().GetMethod("ApplyTheme",
+ System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
+ if (applyThemeMethod != null)
+ {
+ applyThemeMethod.Invoke(this, null);
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"SettingsPanelBase 应用主题时出错: {ex.Message}");
+ }
+ _isLoaded = true;
+ }
+
+ ///
+ /// 为面板中的所有交互控件启用触摸支持
+ ///
+ protected virtual void EnableTouchSupport()
+ {
+ try
+ {
+ // 延迟执行,确保所有控件都已加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ EnableTouchSupportForControls(this);
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"启用触摸支持时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 为控件树中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupportForControls(DependencyObject parent)
+ {
+ if (parent == null) return;
+
+ for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
+ {
+ var child = VisualTreeHelper.GetChild(parent, i);
+
+ // 为 Border 控件(ToggleSwitch、选项按钮等)启用触摸支持
+ if (child is Border border)
+ {
+ // 检查是否是交互控件(有 Tag 或 Cursor 为 Hand)
+ if (border.Tag != null || border.Cursor == Cursors.Hand)
+ {
+ border.IsManipulationEnabled = true;
+
+ // 添加触摸事件支持,将触摸事件转换为鼠标事件
+ border.TouchDown += Border_TouchDown;
+ border.PreviewTouchDown += Border_PreviewTouchDown;
+ }
+ }
+ // 为 Button 控件启用触摸支持
+ else if (child is Button button)
+ {
+ button.IsManipulationEnabled = true;
+ }
+ // 为 ComboBox 启用触摸支持
+ else if (child is ComboBox comboBox)
+ {
+ comboBox.IsManipulationEnabled = true;
+ }
+ // 为 Slider 启用触摸支持
+ else if (child is Slider slider)
+ {
+ slider.IsManipulationEnabled = true;
+ }
+ // 为 TextBox 启用触摸支持
+ else if (child is TextBox textBox)
+ {
+ textBox.IsManipulationEnabled = true;
+ }
+
+ // 递归处理子元素
+ EnableTouchSupportForControls(child);
+ }
+ }
+
+ ///
+ /// Border 触摸按下事件处理
+ ///
+ private void Border_TouchDown(object sender, TouchEventArgs e)
+ {
+ var border = sender as Border;
+ if (border == null) return;
+
+ // 获取触摸点位置
+ var touchPoint = e.GetTouchPoint(border);
+
+ // 创建模拟的鼠标事件
+ var mouseButtonEventArgs = new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left)
+ {
+ RoutedEvent = UIElement.MouseLeftButtonDownEvent,
+ Source = border
+ };
+
+ // 触发鼠标按下事件
+ border.RaiseEvent(mouseButtonEventArgs);
+
+ // 捕获触摸设备
+ border.CaptureTouch(e.TouchDevice);
+ e.Handled = true;
+ }
+
+ ///
+ /// Border 预览触摸按下事件处理
+ ///
+ private void Border_PreviewTouchDown(object sender, TouchEventArgs e)
+ {
+ var border = sender as Border;
+ if (border == null) return;
+
+ // 获取触摸点位置
+ var touchPoint = e.GetTouchPoint(border);
+
+ // 创建模拟的鼠标事件
+ var mouseButtonEventArgs = new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left)
+ {
+ RoutedEvent = UIElement.PreviewMouseLeftButtonDownEvent,
+ Source = border
+ };
+
+ // 触发预览鼠标按下事件
+ border.RaiseEvent(mouseButtonEventArgs);
+
+ e.Handled = true;
+ }
+
+ ///
+ /// 加载设置到UI - 子类需要实现
+ ///
+ public abstract void LoadSettings();
+
+ ///
+ /// 查找ToggleSwitch控件
+ ///
+ protected Border FindToggleSwitch(string name)
+ {
+ return this.FindDescendantByName(name) as Border;
+ }
+
+ ///
+ /// 设置ToggleSwitch状态
+ ///
+ protected 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));
+ var innerBorder = toggleSwitch.Child as Border;
+ if (innerBorder != null)
+ {
+ innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
+ }
+ }
+
+ ///
+ /// 通用的ToggleSwitch点击事件处理
+ ///
+ protected virtual void ToggleSwitch_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ bool isOn = border.Background.ToString() == "#FF3584E4";
+ bool newState = !isOn;
+ SetToggleSwitchState(border, newState);
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ HandleToggleSwitchChange(tag, newState);
+ }
+
+ ///
+ /// 处理ToggleSwitch变化 - 子类需要实现
+ ///
+ protected abstract void HandleToggleSwitchChange(string tag, bool newState);
+
+ ///
+ /// 处理选项按钮变化 - 子类可以重写
+ ///
+ protected virtual void HandleOptionButtonChange(object sender, string tag)
+ {
+ // 默认实现:清除同组其他按钮的选中状态
+ var border = sender as Border;
+ if (border == null) return;
+
+ string[] parts = tag.Split('_');
+ if (parts.Length >= 2)
+ {
+ string group = parts[0];
+ string value = parts[1];
+
+ // 清除同组其他按钮的选中状态
+ var parent = border.Parent as Panel;
+ if (parent != null)
+ {
+ foreach (var child in parent.Children)
+ {
+ if (child is Border childBorder && childBorder != border)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ // 设置当前按钮为选中状态
+ border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ var currentTextBlock = border.Child as TextBlock;
+ if (currentTextBlock != null)
+ {
+ currentTextBlock.FontWeight = FontWeights.Bold;
+ }
+
+ HandleOptionChange(group, value);
+ }
+ }
+
+ ///
+ /// 处理选项变化 - 子类需要实现
+ ///
+ protected abstract void HandleOptionChange(string group, string value);
+ }
+}
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ShortcutsPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/ShortcutsPanel.xaml.cs
index 6bb98663..bd20df56 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/ShortcutsPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ShortcutsPanel.xaml.cs
@@ -29,6 +29,21 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"ShortcutsPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml
index a5d19a9b..00dfc551 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml
@@ -36,7 +36,7 @@
-
+
@@ -50,7 +50,7 @@
-
+
@@ -64,7 +64,7 @@
-
+
@@ -78,7 +78,7 @@
-
+
@@ -93,7 +93,7 @@
-
+
@@ -107,12 +107,12 @@
-
-
+
+
-
-
+
+
@@ -128,7 +128,7 @@
-
+
@@ -147,7 +147,8 @@
ItemContainerStyle="{StaticResource ComboBoxItemStyle}"
HorizontalAlignment="Left"
Width="150"
- SelectedIndex="4">
+ SelectedIndex="4"
+ SelectionChanged="ComboBoxAutoDelSavedFilesDaysThreshold_SelectionChanged">
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs
index bdf9eb91..6d7f0dc8 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/SnapshotPanel.xaml.cs
@@ -1,17 +1,54 @@
+using Ink_Canvas;
+using iNKORE.UI.WPF.Helpers;
using System;
+using System.IO;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Media;
+using Application = System.Windows.Application;
namespace Ink_Canvas.Windows.SettingsViews
{
///
/// SnapshotPanel.xaml 的交互逻辑
///
- public partial class SnapshotPanel : UserControl
+ public partial class SnapshotPanel : System.Windows.Controls.UserControl
{
+ private bool _isLoaded = false;
+
public SnapshotPanel()
{
InitializeComponent();
+ Loaded += SnapshotPanel_Loaded;
+ }
+
+ private void SnapshotPanel_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ // 添加触摸支持
+ EnableTouchSupport();
+ // 应用主题
+ ApplyTheme();
+ _isLoaded = true;
+ }
+
+ ///
+ /// 为面板中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupport()
+ {
+ try
+ {
+ // 延迟执行,确保所有控件都已加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ MainWindowSettingsHelper.EnableTouchSupportForControls(this);
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"SnapshotPanel 启用触摸支持时出错: {ex.Message}");
+ }
}
public event EventHandler IsTopBarNeedShadowEffect;
@@ -29,6 +66,311 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 加载设置到UI
+ ///
+ public void LoadSettings()
+ {
+ if (MainWindow.Settings == null) return;
+
+ _isLoaded = false;
+
+ try
+ {
+ // 清屏时自动截图
+ if (MainWindow.Settings.Automation != null)
+ {
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoSaveStrokesAtClear"), MainWindow.Settings.Automation.IsAutoSaveStrokesAtClear);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchSaveScreenshotsInDateFolders"), MainWindow.Settings.Automation.IsSaveScreenshotsInDateFolders);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoSaveStrokesAtScreenshot"), MainWindow.Settings.Automation.IsAutoSaveStrokesAtScreenshot);
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoDelSavedFiles"), MainWindow.Settings.Automation.AutoDelSavedFiles);
+
+ // 自动截图最小墨迹量
+ if (SideControlMinimumAutomationSlider != null)
+ {
+ double minValue = MainWindow.Settings.Automation.MinimumAutomationStrokeNumber;
+ if (minValue == 0) minValue = 1.0;
+ SideControlMinimumAutomationSlider.Value = minValue;
+ if (SideControlMinimumAutomationText != null)
+ {
+ SideControlMinimumAutomationText.Text = minValue.ToString("F2");
+ }
+ }
+
+ // 保存路径
+ if (AutoSavedStrokesLocation != null)
+ {
+ AutoSavedStrokesLocation.Text = MainWindow.Settings.Automation.AutoSavedStrokesLocation;
+ }
+
+ // 自动删除保存时长
+ if (ComboBoxAutoDelSavedFilesDaysThreshold != null)
+ {
+ int days = MainWindow.Settings.Automation.AutoDelSavedFilesDaysThreshold;
+ int selectedIndex = 4; // 默认15天
+ switch (days)
+ {
+ case 1: selectedIndex = 0; break;
+ case 3: selectedIndex = 1; break;
+ case 5: selectedIndex = 2; break;
+ case 7: selectedIndex = 3; break;
+ case 15: selectedIndex = 4; break;
+ case 30: selectedIndex = 5; break;
+ case 60: selectedIndex = 6; break;
+ case 100: selectedIndex = 7; break;
+ case 365: selectedIndex = 8; break;
+ }
+ ComboBoxAutoDelSavedFilesDaysThreshold.SelectedIndex = selectedIndex;
+ }
+
+ if (AutoDelIntervalPanel != null)
+ {
+ AutoDelIntervalPanel.Visibility = MainWindow.Settings.Automation.AutoDelSavedFiles ? Visibility.Visible : Visibility.Collapsed;
+ }
+ }
+
+ // 自动幻灯片截屏
+ if (MainWindow.Settings.PowerPointSettings != null)
+ {
+ SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoSaveScreenShotInPowerPoint"), MainWindow.Settings.PowerPointSettings.IsAutoSaveScreenShotInPowerPoint);
+ }
+ }
+ catch (Exception ex)
+ {
+ 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));
+ var innerBorder = toggleSwitch.Child as Border;
+ if (innerBorder != null)
+ {
+ innerBorder.HorizontalAlignment = isOn ? System.Windows.HorizontalAlignment.Right : System.Windows.HorizontalAlignment.Left;
+ }
+ }
+
+ ///
+ /// ToggleSwitch点击事件处理
+ ///
+ private void ToggleSwitch_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ bool isOn = border.Background.ToString() == "#FF3584E4";
+ bool newState = !isOn;
+ SetToggleSwitchState(border, newState);
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ switch (tag)
+ {
+ case "AutoSaveStrokesAtClear":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoSaveStrokesAtClear", newState);
+ break;
+
+ case "SaveScreenshotsInDateFolders":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchSaveScreenshotsInDateFolders", newState);
+ break;
+
+ case "AutoSaveStrokesAtScreenshot":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoSaveStrokesAtScreenshot", newState);
+ break;
+
+ case "AutoSaveScreenShotInPowerPoint":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoSaveScreenShotInPowerPoint", newState);
+ break;
+
+ case "AutoDelSavedFiles":
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoDelSavedFiles", newState);
+ // 更新UI状态
+ if (AutoDelIntervalPanel != null)
+ {
+ AutoDelIntervalPanel.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
+ }
+ break;
+ }
+ }
+
+ ///
+ /// Slider值变化事件处理
+ ///
+ private void SideControlMinimumAutomationSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (SideControlMinimumAutomationSlider != null && SideControlMinimumAutomationText != null)
+ {
+ double value = SideControlMinimumAutomationSlider.Value;
+ SideControlMinimumAutomationText.Text = value.ToString("F2");
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeSliderValueChanged("SideControlMinimumAutomationSlider", value);
+ }
+ }
+
+ ///
+ /// 保存路径文本框变化事件处理
+ ///
+ private void AutoSavedStrokesLocation_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (AutoSavedStrokesLocation != null)
+ {
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeTextBoxTextChanged("AutoSavedStrokesLocation", AutoSavedStrokesLocation.Text);
+ }
+ }
+
+ ///
+ /// 浏览按钮点击事件处理
+ ///
+ private void AutoSavedStrokesLocationButton_Click(object sender, RoutedEventArgs e)
+ {
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeMainWindowMethod("AutoSavedStrokesLocationButton_Click", sender, e);
+ // 同步新面板中的文本框
+ if (AutoSavedStrokesLocation != null)
+ {
+ var mainWindow = Application.Current.MainWindow as MainWindow;
+ if (mainWindow != null)
+ {
+ var textBox = mainWindow.FindName("AutoSavedStrokesLocation") as System.Windows.Controls.TextBox;
+ if (textBox != null)
+ {
+ AutoSavedStrokesLocation.Text = textBox.Text;
+ }
+ }
+ }
+ }
+
+ ///
+ /// 设置保存到 D:\Ink Canvas 按钮点击事件处理
+ ///
+ private void SetAutoSavedStrokesLocationToDiskDButton_Click(object sender, RoutedEventArgs e)
+ {
+ // 调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeMainWindowMethod("SetAutoSavedStrokesLocationToDiskDButton_Click", sender, e);
+ // 同步新面板中的文本框
+ if (AutoSavedStrokesLocation != null)
+ {
+ var mainWindow = Application.Current.MainWindow as MainWindow;
+ if (mainWindow != null)
+ {
+ var textBox = mainWindow.FindName("AutoSavedStrokesLocation") as System.Windows.Controls.TextBox;
+ if (textBox != null)
+ {
+ AutoSavedStrokesLocation.Text = textBox.Text;
+ }
+ }
+ }
+ }
+
+ ///
+ /// 设置保存到文档按钮点击事件处理
+ ///
+ private void SetAutoSavedStrokesLocationToDocumentFolderButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (AutoSavedStrokesLocation != null)
+ {
+ string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+ AutoSavedStrokesLocation.Text = Path.Combine(documentsPath, "Ink Canvas");
+ }
+ }
+
+ ///
+ /// ComboBox选择变化事件处理
+ ///
+ private void ComboBoxAutoDelSavedFilesDaysThreshold_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (ComboBoxAutoDelSavedFilesDaysThreshold?.SelectedItem is ComboBoxItem selectedItem)
+ {
+ // 调用 MainWindow 中的方法
+ var mainWindow = Application.Current.MainWindow as MainWindow;
+ if (mainWindow != null)
+ {
+ var comboBox = mainWindow.FindName("ComboBoxAutoDelSavedFilesDaysThreshold") as System.Windows.Controls.ComboBox;
+ if (comboBox != null)
+ {
+ // 找到对应的选项并设置
+ string tag = selectedItem.Tag?.ToString();
+ if (!string.IsNullOrEmpty(tag) && tag.StartsWith("AutoDelSavedFilesDaysThreshold_"))
+ {
+ string daysStr = tag.Replace("AutoDelSavedFilesDaysThreshold_", "");
+ foreach (ComboBoxItem item in comboBox.Items)
+ {
+ if (item.Tag?.ToString() == tag || item.Content?.ToString() == daysStr + "天")
+ {
+ comboBox.SelectedItem = item;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxAutoDelSavedFilesDaysThreshold", item);
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置
+ string tag = selectedItem.Tag?.ToString();
+ if (!string.IsNullOrEmpty(tag) && tag.StartsWith("AutoDelSavedFilesDaysThreshold_"))
+ {
+ string daysStr = tag.Replace("AutoDelSavedFilesDaysThreshold_", "");
+ if (int.TryParse(daysStr, out int days))
+ {
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ if (MainWindow.Settings.Automation != null)
+ {
+ MainWindow.Settings.Automation.AutoDelSavedFilesDaysThreshold = days;
+ }
+ }, "ComboBoxAutoDelSavedFilesDaysThreshold");
+ }
+ }
+ }
+ }
+ }
+ }
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"SnapshotPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml
index 5c88eed9..bf6f449d 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml
@@ -35,7 +35,7 @@
-
+
@@ -49,7 +49,7 @@
-
+
@@ -63,7 +63,7 @@
-
+
@@ -77,7 +77,7 @@
-
+
@@ -96,7 +96,7 @@
-
+
@@ -110,7 +110,7 @@
-
+
@@ -125,10 +125,10 @@
-
+
-
+
@@ -139,7 +139,7 @@
-
+
@@ -147,7 +147,7 @@
-
+
@@ -155,7 +155,7 @@
-
+
@@ -169,7 +169,8 @@
ItemContainerStyle="{StaticResource ComboBoxItemStyle}"
HorizontalAlignment="Left"
Width="150"
- SelectedIndex="6">
+ SelectedIndex="6"
+ SelectionChanged="AutoUpdateWithSilenceStartTimeComboBox_SelectionChanged">
@@ -203,7 +204,8 @@
ItemContainerStyle="{StaticResource ComboBoxItemStyle}"
HorizontalAlignment="Left"
Width="150"
- SelectedIndex="22">
+ SelectedIndex="22"
+ SelectionChanged="AutoUpdateWithSilenceEndTimeComboBox_SelectionChanged">
@@ -246,7 +248,7 @@
-
+
@@ -260,7 +262,7 @@
-
+
@@ -281,7 +283,7 @@
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs
index af4f03f6..488c49cf 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs
@@ -1,6 +1,10 @@
+using Ink_Canvas;
+using iNKORE.UI.WPF.Helpers;
using System;
+using System.Linq;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Media;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -9,9 +13,50 @@ namespace Ink_Canvas.Windows.SettingsViews
///
public partial class StartupPanel : UserControl
{
+ private bool _isLoaded = false;
+
public StartupPanel()
{
InitializeComponent();
+ Loaded += StartupPanel_Loaded;
+ }
+
+ private void StartupPanel_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ // 添加触摸支持
+ EnableTouchSupport();
+ // 应用主题
+ ApplyTheme();
+ _isLoaded = true;
+ }
+
+ ///
+ /// 为面板中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupport()
+ {
+ try
+ {
+ // 延迟执行,确保所有控件都已加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ EnableTouchSupportForControls(this);
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"StartupPanel 启用触摸支持时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 为控件树中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupportForControls(System.Windows.DependencyObject parent)
+ {
+ // 使用 MainWindowSettingsHelper 的通用方法
+ MainWindowSettingsHelper.EnableTouchSupportForControls(parent);
}
public event EventHandler IsTopBarNeedShadowEffect;
@@ -29,6 +74,447 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 加载设置到UI
+ ///
+ public void LoadSettings()
+ {
+ if (MainWindow.Settings == null) return;
+
+ _isLoaded = false;
+
+ try
+ {
+ // 自动更新设置
+ var toggleSwitchIsAutoUpdate = FindToggleSwitch("ToggleSwitchIsAutoUpdate");
+ if (toggleSwitchIsAutoUpdate != null)
+ {
+ bool isAutoUpdate = MainWindow.Settings.Startup.IsAutoUpdate;
+ SetToggleSwitchState(toggleSwitchIsAutoUpdate, isAutoUpdate);
+ }
+
+ // 静默更新设置
+ var toggleSwitchIsAutoUpdateWithSilence = FindToggleSwitch("ToggleSwitchIsAutoUpdateWithSilence");
+ if (toggleSwitchIsAutoUpdateWithSilence != null)
+ {
+ bool isAutoUpdateWithSilence = MainWindow.Settings.Startup.IsAutoUpdateWithSilence;
+ 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()
+ .FirstOrDefault(item => item.Tag?.ToString() == startTime.Replace(":", ""));
+ if (startItem != null)
+ {
+ AutoUpdateWithSilenceStartTimeComboBox.SelectedItem = startItem;
+ }
+ }
+
+ if (AutoUpdateWithSilenceEndTimeComboBox != null)
+ {
+ var endTime = MainWindow.Settings.Startup.AutoUpdateWithSilenceEndTime ?? "22:00";
+ var endItem = AutoUpdateWithSilenceEndTimeComboBox.Items.Cast()
+ .FirstOrDefault(item => item.Tag?.ToString() == endTime.Replace(":", ""));
+ if (endItem != null)
+ {
+ 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);
+ }
+ else
+ {
+ UpdateUpdateChannelButtons(false);
+ }
+
+ // 仅PPT模式
+ var toggleSwitchMode = FindToggleSwitch("ToggleSwitchMode");
+ if (toggleSwitchMode != null && MainWindow.Settings.ModeSettings != null)
+ {
+ SetToggleSwitchState(toggleSwitchMode, MainWindow.Settings.ModeSettings.IsPPTOnlyMode);
+ }
+ }
+ catch (Exception ex)
+ {
+ 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));
+ 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;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ bool isOn = border.Background.ToString() == "#FF3584E4";
+ bool newState = !isOn;
+ SetToggleSwitchState(border, newState);
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ switch (tag)
+ {
+ case "IsAutoUpdate":
+ // 直接调用 MainWindow 中的方法
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsAutoUpdate", newState);
+ // 更新UI状态
+ var toggleSwitchIsAutoUpdateWithSilence = FindToggleSwitch("ToggleSwitchIsAutoUpdateWithSilence");
+ if (toggleSwitchIsAutoUpdateWithSilence != null)
+ {
+ toggleSwitchIsAutoUpdateWithSilence.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
+ }
+ if (AutoUpdateTimePeriodBlock != null)
+ {
+ AutoUpdateTimePeriodBlock.Visibility =
+ (MainWindow.Settings.Startup.IsAutoUpdateWithSilence && MainWindow.Settings.Startup.IsAutoUpdate) ?
+ Visibility.Visible : Visibility.Collapsed;
+ }
+ 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)
+ {
+ 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)
+ {
+ MainWindow.Settings.Advanced.IsAlwaysOnTop = newState;
+ }
+ }, "ToggleSwitchAlwaysOnTop");
+ // 调用 SetAlwaysOnTop 方法(如果存在)
+ MainWindowSettingsHelper.InvokeMainWindowMethod("SetAlwaysOnTop", newState);
+ break;
+
+ case "UIAccessTopMost":
+ // UIA置顶
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ if (MainWindow.Settings.Advanced != null)
+ {
+ MainWindow.Settings.Advanced.EnableUIAccessTopMost = newState;
+ }
+ }, "ToggleSwitchUIAccessTopMost");
+ break;
+
+ case "Mode":
+ // 仅PPT模式
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchMode", newState);
+ break;
+ }
+ }
+
+ ///
+ /// 选项按钮点击事件处理
+ ///
+ private void OptionButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ 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);
+ 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);
+ break;
+ }
+ }
+
+ ///
+ /// 更新更新通道按钮状态
+ ///
+ private void UpdateUpdateChannelButtons(bool isReleaseSelected)
+ {
+ try
+ {
+ bool isDarkTheme = ThemeHelper.IsDarkTheme;
+
+ if (UpdateChannelReleaseBorder != null)
+ {
+ UpdateChannelReleaseBorder.Background = isReleaseSelected
+ ? (isDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225)))
+ : (isDarkTheme ? new SolidColorBrush(Color.FromRgb(35, 35, 35)) : new SolidColorBrush(Colors.Transparent));
+ var textBlock = UpdateChannelReleaseBorder.Child as TextBlock;
+ if (textBlock != null)
+ {
+ textBlock.FontWeight = isReleaseSelected ? FontWeights.Bold : FontWeights.Normal;
+ textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+ }
+
+ if (UpdateChannelBetaBorder != null)
+ {
+ UpdateChannelBetaBorder.Background = !isReleaseSelected
+ ? (isDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225)))
+ : (isDarkTheme ? new SolidColorBrush(Color.FromRgb(35, 35, 35)) : new SolidColorBrush(Colors.Transparent));
+ var textBlock = UpdateChannelBetaBorder.Child as TextBlock;
+ if (textBlock != null)
+ {
+ textBlock.FontWeight = !isReleaseSelected ? FontWeights.Bold : FontWeights.Normal;
+ textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+ }
+ }
+ 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 (UpdateChannelReleaseBorder != null)
+ {
+ UpdateChannelReleaseBorder.Background = isDarkTheme
+ ? ThemeHelper.GetButtonBackgroundBrush()
+ : new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ var textBlock = UpdateChannelReleaseBorder.Child as TextBlock;
+ if (textBlock != null)
+ {
+ textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+ }
+ if (UpdateChannelBetaBorder != null)
+ {
+ UpdateChannelBetaBorder.Background = isDarkTheme
+ ? new SolidColorBrush(Color.FromRgb(35, 35, 35))
+ : new SolidColorBrush(Colors.Transparent);
+ var textBlock = UpdateChannelBetaBorder.Child as TextBlock;
+ if (textBlock != null)
+ {
+ textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+ }
+
+ // 更新按钮
+ if (ManualUpdateButton != null)
+ {
+ ManualUpdateButton.Background = ThemeHelper.GetButtonBackgroundBrush();
+ ManualUpdateButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+ if (FixVersionButton != null)
+ {
+ FixVersionButton.Background = ThemeHelper.GetButtonBackgroundBrush();
+ FixVersionButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+ if (HistoryRollbackButton != null)
+ {
+ HistoryRollbackButton.Background = ThemeHelper.GetButtonBackgroundBrush();
+ HistoryRollbackButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+
+ // 使用 ThemeHelper 递归更新其他元素
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"StartupPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StoragePanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/StoragePanel.xaml.cs
index f2fb47d8..f4adcd5a 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StoragePanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StoragePanel.xaml.cs
@@ -29,6 +29,21 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"StoragePanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs
new file mode 100644
index 00000000..7bcedb6e
--- /dev/null
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs
@@ -0,0 +1,470 @@
+using System.Windows.Media;
+using Ink_Canvas;
+
+namespace Ink_Canvas.Windows.SettingsViews
+{
+ ///
+ /// 主题辅助类:提供统一的主题颜色资源
+ ///
+ public static class ThemeHelper
+ {
+ ///
+ /// 检查当前是否为深色主题
+ ///
+ public static bool IsDarkTheme
+ {
+ get
+ {
+ if (MainWindow.Settings?.Appearance == null) return false;
+ return MainWindow.Settings.Appearance.Theme == 1 ||
+ (MainWindow.Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
+ }
+ }
+
+ ///
+ /// 检查系统主题是否为浅色
+ ///
+ private static bool IsSystemThemeLight()
+ {
+ try
+ {
+ var registryKey = Microsoft.Win32.Registry.CurrentUser;
+ var themeKey = registryKey.OpenSubKey("software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
+ var keyValue = 0;
+ if (themeKey != null) keyValue = (int)themeKey.GetValue("SystemUsesLightTheme");
+ return keyValue == 1;
+ }
+ catch
+ {
+ return true; // 默认返回浅色主题
+ }
+ }
+
+ // 文字颜色 - 参考 Windows 系统设置
+ public static Color TextPrimary => IsDarkTheme ? Color.FromRgb(243, 243, 243) : Color.FromRgb(0, 0, 0); // Windows 系统主文字颜色
+ public static Color TextSecondary => IsDarkTheme ? Color.FromRgb(200, 200, 200) : Color.FromRgb(96, 96, 96); // Windows 系统次要文字颜色
+ public static Color TextTertiary => IsDarkTheme ? Color.FromRgb(161, 161, 161) : Color.FromRgb(120, 120, 120); // Windows 系统三级文字颜色
+
+ // 背景颜色 - 参考 Windows 系统设置
+ public static Color BackgroundPrimary => IsDarkTheme ? Color.FromRgb(32, 32, 32) : Color.FromRgb(255, 255, 255); // Windows 系统主背景
+ public static Color BackgroundSecondary => IsDarkTheme ? Color.FromRgb(25, 25, 25) : Color.FromRgb(243, 243, 243); // Windows 系统次要背景(侧边栏等)
+ public static Color BackgroundTertiary => IsDarkTheme ? Color.FromRgb(43, 43, 43) : Color.FromRgb(237, 237, 237); // Windows 系统三级背景(按钮等)
+
+ // 边框颜色 - 参考 Windows 系统设置
+ public static Color BorderPrimary => IsDarkTheme ? Color.FromRgb(62, 62, 62) : Color.FromRgb(229, 229, 229); // Windows 系统主边框
+ public static Color BorderSecondary => IsDarkTheme ? Color.FromRgb(55, 55, 55) : Color.FromRgb(220, 220, 220); // Windows 系统次要边框
+ public static Color BorderTertiary => IsDarkTheme ? Color.FromRgb(70, 70, 70) : Color.FromRgb(211, 211, 211); // Windows 系统三级边框
+
+ // 分隔线颜色 - 参考 Windows 系统设置
+ public static Color Separator => IsDarkTheme ? Color.FromRgb(62, 62, 62) : Color.FromRgb(237, 237, 237); // Windows 系统分隔线
+
+ // 选中/高亮颜色 - 参考 Windows 系统设置
+ public static Color SelectedBackground => IsDarkTheme ? Color.FromRgb(62, 62, 62) : Color.FromRgb(237, 237, 237); // Windows 系统选中背景
+ public static Color HoverBackground => IsDarkTheme ? Color.FromRgb(43, 43, 43) : Color.FromRgb(243, 243, 243); // Windows 系统悬停背景
+
+ // 按钮颜色 - 参考 Windows 系统设置
+ public static Color ButtonBackground => IsDarkTheme ? Color.FromRgb(43, 43, 43) : Color.FromRgb(237, 237, 237); // Windows 系统按钮背景
+ public static Color ButtonHoverBackground => IsDarkTheme ? Color.FromRgb(55, 55, 55) : Color.FromRgb(220, 220, 220); // Windows 系统按钮悬停背景
+
+ // 文本框颜色 - 参考 Windows 系统设置
+ public static Color TextBoxBackground => IsDarkTheme ? Color.FromRgb(43, 43, 43) : Color.FromRgb(255, 255, 255); // Windows 系统文本框背景
+ public static Color TextBoxBorder => IsDarkTheme ? Color.FromRgb(62, 62, 62) : Color.FromRgb(229, 229, 229); // Windows 系统文本框边框
+
+ // 滚动条颜色 - 参考 Windows 系统设置
+ public static Color ScrollBarTrack => IsDarkTheme ? Color.FromRgb(25, 25, 25) : Color.FromRgb(243, 243, 243); // Windows 系统滚动条轨道
+ public static Color ScrollBarThumb => IsDarkTheme ? Color.FromRgb(122, 122, 122) : Color.FromRgb(191, 191, 191); // Windows 系统滚动条滑块
+ public static Color ScrollBarThumbHover => IsDarkTheme ? Color.FromRgb(150, 150, 150) : Color.FromRgb(138, 138, 138); // Windows 系统滚动条滑块悬停
+
+ // 转换为 SolidColorBrush
+ public static SolidColorBrush GetTextPrimaryBrush() => new SolidColorBrush(TextPrimary);
+ public static SolidColorBrush GetTextSecondaryBrush() => new SolidColorBrush(TextSecondary);
+ public static SolidColorBrush GetTextTertiaryBrush() => new SolidColorBrush(TextTertiary);
+ public static SolidColorBrush GetBackgroundPrimaryBrush() => new SolidColorBrush(BackgroundPrimary);
+ public static SolidColorBrush GetBackgroundSecondaryBrush() => new SolidColorBrush(BackgroundSecondary);
+ public static SolidColorBrush GetBackgroundTertiaryBrush() => new SolidColorBrush(BackgroundTertiary);
+ public static SolidColorBrush GetBorderPrimaryBrush() => new SolidColorBrush(BorderPrimary);
+ public static SolidColorBrush GetBorderSecondaryBrush() => new SolidColorBrush(BorderSecondary);
+ public static SolidColorBrush GetBorderTertiaryBrush() => new SolidColorBrush(BorderTertiary);
+ public static SolidColorBrush GetSeparatorBrush() => new SolidColorBrush(Separator);
+ public static SolidColorBrush GetSelectedBackgroundBrush() => new SolidColorBrush(SelectedBackground);
+ public static SolidColorBrush GetHoverBackgroundBrush() => new SolidColorBrush(HoverBackground);
+ public static SolidColorBrush GetButtonBackgroundBrush() => new SolidColorBrush(ButtonBackground);
+ public static SolidColorBrush GetButtonHoverBackgroundBrush() => new SolidColorBrush(ButtonHoverBackground);
+ public static SolidColorBrush GetTextBoxBackgroundBrush() => new SolidColorBrush(TextBoxBackground);
+ public static SolidColorBrush GetTextBoxBorderBrush() => new SolidColorBrush(TextBoxBorder);
+ public static SolidColorBrush GetScrollBarTrackBrush() => new SolidColorBrush(ScrollBarTrack);
+ public static SolidColorBrush GetScrollBarThumbBrush() => new SolidColorBrush(ScrollBarThumb);
+ public static SolidColorBrush GetScrollBarThumbHoverBrush() => new SolidColorBrush(ScrollBarThumbHover);
+
+ ///
+ /// 更新控件的文字颜色
+ ///
+ public static void UpdateTextBlockColors(System.Windows.DependencyObject parent)
+ {
+ for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); i++)
+ {
+ var child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
+ if (child is System.Windows.Controls.TextBlock textBlock)
+ {
+ var foreground = textBlock.Foreground as SolidColorBrush;
+ if (foreground != null)
+ {
+ var color = foreground.Color;
+ // 检查是否是硬编码的浅色主题颜色
+ if (color.R == 46 && color.G == 52 && color.B == 54) // #2e3436 - 主文字
+ {
+ textBlock.Foreground = GetTextPrimaryBrush();
+ }
+ else if (color.R == 154 && color.G == 153 && color.B == 150) // #9a9996 - 次要文字
+ {
+ textBlock.Foreground = GetTextSecondaryBrush();
+ }
+ else if (color.R == 34 && color.G == 34 && color.B == 34) // #222222 - 深色文字
+ {
+ textBlock.Foreground = GetTextPrimaryBrush();
+ }
+ }
+ }
+ UpdateTextBlockColors(child);
+ }
+ }
+
+ ///
+ /// 更新控件的边框和背景颜色
+ ///
+ public static void UpdateBorderColors(System.Windows.DependencyObject parent)
+ {
+ for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); i++)
+ {
+ var child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
+ if (child is System.Windows.Controls.Border border)
+ {
+ var background = border.Background as SolidColorBrush;
+ if (background != null)
+ {
+ var color = background.Color;
+ // 检查是否是硬编码的浅色主题颜色
+ if (color.R == 235 && color.G == 235 && color.B == 235) // #ebebeb - 分隔线
+ {
+ border.Background = GetSeparatorBrush();
+ }
+ else if (color.R == 217 && color.G == 217 && color.B == 217) // #d9d9d9 - 按钮背景
+ {
+ border.Background = GetButtonBackgroundBrush();
+ }
+ else if (color.R == 225 && color.G == 225 && color.B == 225) // #e1e1e1 - 按钮背景/分隔线
+ {
+ // 检查是否是按钮(有内边距或特定尺寸)
+ if (border.Padding.Left > 0 || border.Padding.Top > 0 ||
+ (border.Width > 0 && border.Height > 0 && border.Width < 200 && border.Height < 100))
+ {
+ border.Background = GetButtonBackgroundBrush();
+ }
+ else
+ {
+ // 可能是分隔线
+ border.Background = GetSeparatorBrush();
+ }
+ }
+ else if (color.R == 255 && color.G == 255 && color.B == 255) // White - 白色背景
+ {
+ // 检查是否是搜索结果项(有圆角和内边距)
+ if (border.CornerRadius.TopLeft == 6 && border.CornerRadius.TopRight == 6 &&
+ border.CornerRadius.BottomLeft == 6 && border.CornerRadius.BottomRight == 6 &&
+ border.Padding.Left > 0 && border.Padding.Top > 0)
+ {
+ // 搜索结果项背景
+ border.Background = IsDarkTheme
+ ? new SolidColorBrush(Color.FromRgb(43, 43, 43)) // 深色主题搜索结果项背景
+ : new SolidColorBrush(Colors.White);
+ }
+ else
+ {
+ // 其他白色背景(如搜索框)
+ border.Background = GetTextBoxBackgroundBrush();
+ }
+ }
+ else if (color.R == 250 && color.G == 250 && color.B == 250) // #fafafa - 主背景
+ {
+ border.Background = GetBackgroundPrimaryBrush();
+ }
+ }
+
+ var borderBrush = border.BorderBrush as SolidColorBrush;
+ if (borderBrush != null)
+ {
+ var color = borderBrush.Color;
+ if (color.R == 230 && color.G == 230 && color.B == 230) // #e6e6e6 - 边框
+ {
+ border.BorderBrush = GetBorderPrimaryBrush();
+ }
+ else if (color.R == 225 && color.G == 225 && color.B == 225) // #e1e1e1 - 边框
+ {
+ border.BorderBrush = GetBorderPrimaryBrush();
+ }
+ else if (color.R == 211 && color.G == 211 && color.B == 211) // #d3d3d3 - 边框
+ {
+ border.BorderBrush = GetBorderTertiaryBrush();
+ }
+ }
+ }
+ UpdateBorderColors(child);
+ }
+ }
+
+ ///
+ /// 更新控件的线条颜色
+ ///
+ public static void UpdateLineColors(System.Windows.DependencyObject parent)
+ {
+ for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); i++)
+ {
+ var child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
+ if (child is System.Windows.Shapes.Line line)
+ {
+ var stroke = line.Stroke as SolidColorBrush;
+ if (stroke != null)
+ {
+ var color = stroke.Color;
+ if (color.R == 211 && color.G == 211 && color.B == 211) // #d3d3d3 - 分隔线
+ {
+ line.Stroke = GetSeparatorBrush();
+ }
+ }
+ }
+ UpdateLineColors(child);
+ }
+ }
+
+ ///
+ /// 更新控件的文本框和组合框颜色
+ ///
+ public static void UpdateInputControlsColors(System.Windows.DependencyObject parent)
+ {
+ for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); i++)
+ {
+ var child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
+ if (child is System.Windows.Controls.TextBox textBox)
+ {
+ var foreground = textBox.Foreground as SolidColorBrush;
+ if (foreground != null)
+ {
+ var color = foreground.Color;
+ if (color.R == 46 && color.G == 52 && color.B == 54) // #2e3436
+ {
+ textBox.Foreground = GetTextPrimaryBrush();
+ }
+ }
+ var background = textBox.Background as SolidColorBrush;
+ if (background != null)
+ {
+ var color = background.Color;
+ if (color.R == 255 && color.G == 255 && color.B == 255) // 白色背景
+ {
+ textBox.Background = IsDarkTheme ? GetBackgroundSecondaryBrush() : new SolidColorBrush(System.Windows.Media.Colors.White);
+ }
+ }
+ }
+ else if (child is System.Windows.Controls.ComboBox comboBox)
+ {
+ var foreground = comboBox.Foreground as SolidColorBrush;
+ if (foreground != null)
+ {
+ var color = foreground.Color;
+ if (color.R == 46 && color.G == 52 && color.B == 54) // #2e3436
+ {
+ comboBox.Foreground = GetTextPrimaryBrush();
+ }
+ }
+ }
+ UpdateInputControlsColors(child);
+ }
+ }
+
+ ///
+ /// 更新控件的按钮颜色
+ ///
+ public static void UpdateButtonColors(System.Windows.DependencyObject parent)
+ {
+ for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); i++)
+ {
+ var child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
+ if (child is System.Windows.Controls.Button button)
+ {
+ var background = button.Background as SolidColorBrush;
+ if (background != null)
+ {
+ var color = background.Color;
+ // 检查是否是默认按钮(没有特定背景色)或特定颜色的按钮
+ if (color.R == 37 && color.G == 99 && color.B == 235) // #2563eb - 蓝色按钮(保持原色)
+ {
+ // 蓝色按钮保持原色,但更新文字颜色
+ if (button.Foreground is SolidColorBrush fgBrush &&
+ fgBrush.Color.R == 255 && fgBrush.Color.G == 255 && fgBrush.Color.B == 255)
+ {
+ button.Foreground = new SolidColorBrush(Colors.White); // 保持白色文字
+ }
+ }
+ else if (color.R == 255 && color.G == 255 && color.B == 255) // 白色背景按钮
+ {
+ button.Background = GetButtonBackgroundBrush();
+ button.Foreground = GetTextPrimaryBrush();
+ }
+ else if (color.A == 0 || color == System.Windows.Media.Colors.Transparent) // 透明背景
+ {
+ // 透明背景按钮,只更新文字颜色
+ button.Foreground = GetTextPrimaryBrush();
+ }
+ }
+ else
+ {
+ // 没有背景色的按钮,更新文字颜色
+ button.Foreground = GetTextPrimaryBrush();
+ }
+ }
+ UpdateButtonColors(child);
+ }
+ }
+
+ ///
+ /// 更新控件中的图标颜色
+ ///
+ public static void UpdateImageIconColors(System.Windows.DependencyObject parent)
+ {
+ for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); i++)
+ {
+ var child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
+ if (child is System.Windows.Controls.Image image && image.Source is DrawingImage drawingImage)
+ {
+ if (drawingImage.Drawing is DrawingGroup drawingGroup)
+ {
+ Color iconColor = IsDarkTheme
+ ? Color.FromRgb(243, 243, 243) // 深色主题使用浅色图标 #F3F3F3
+ : Color.FromRgb(34, 34, 34); // 浅色主题使用深色图标 #222222
+
+ // 检查图标是否使用了深色(需要更新的颜色)
+ bool needsUpdate = false;
+ foreach (var drawing in drawingGroup.Children)
+ {
+ if (drawing is GeometryDrawing geometryDrawing)
+ {
+ if (geometryDrawing.Brush is SolidColorBrush brush)
+ {
+ var color = brush.Color;
+ if (color.R == 34 && color.G == 34 && color.B == 34) // #222222
+ {
+ needsUpdate = true;
+ break;
+ }
+ }
+ if (geometryDrawing.Pen?.Brush is SolidColorBrush penBrush)
+ {
+ var color = penBrush.Color;
+ if (color.R == 34 && color.G == 34 && color.B == 34) // #222222
+ {
+ needsUpdate = true;
+ break;
+ }
+ }
+ }
+ }
+
+ if (needsUpdate)
+ {
+ // 克隆并更新图标颜色
+ var clonedDrawing = CloneDrawingGroupForTheme(drawingGroup, iconColor);
+ image.Source = new DrawingImage { Drawing = clonedDrawing };
+ }
+ }
+ }
+ UpdateImageIconColors(child);
+ }
+ }
+
+ ///
+ /// 克隆 DrawingGroup 并更新颜色(用于主题适配)
+ ///
+ private static DrawingGroup CloneDrawingGroupForTheme(DrawingGroup source, Color newColor)
+ {
+ var cloned = new DrawingGroup();
+ cloned.ClipGeometry = source.ClipGeometry?.Clone();
+ cloned.Opacity = source.Opacity;
+ cloned.Transform = source.Transform?.Clone();
+
+ foreach (var drawing in source.Children)
+ {
+ if (drawing is GeometryDrawing geometryDrawing)
+ {
+ var clonedGeometry = geometryDrawing.Geometry?.Clone();
+ var clonedBrush = CloneBrushForTheme(geometryDrawing.Brush, newColor);
+ var clonedPen = geometryDrawing.Pen != null
+ ? ClonePenForTheme(geometryDrawing.Pen, newColor)
+ : null;
+
+ cloned.Children.Add(new GeometryDrawing(clonedBrush, clonedPen, clonedGeometry));
+ }
+ else if (drawing is DrawingGroup subGroup)
+ {
+ cloned.Children.Add(CloneDrawingGroupForTheme(subGroup, newColor));
+ }
+ else
+ {
+ cloned.Children.Add(drawing);
+ }
+ }
+
+ return cloned;
+ }
+
+ ///
+ /// 克隆 Brush 并更新颜色(用于主题适配)
+ ///
+ private static Brush CloneBrushForTheme(Brush source, Color newColor)
+ {
+ if (source is SolidColorBrush solidBrush)
+ {
+ var originalColor = solidBrush.Color;
+ if (originalColor.R == 34 && originalColor.G == 34 && originalColor.B == 34) // #222222
+ {
+ return new SolidColorBrush(newColor) { Opacity = solidBrush.Opacity };
+ }
+ else if (originalColor.A > 0 && originalColor != Colors.Transparent &&
+ originalColor.R < 50 && originalColor.G < 50 && originalColor.B < 50) // 深色
+ {
+ return new SolidColorBrush(newColor) { Opacity = solidBrush.Opacity };
+ }
+ return new SolidColorBrush(originalColor) { Opacity = solidBrush.Opacity };
+ }
+ return source?.Clone();
+ }
+
+ ///
+ /// 克隆 Pen 并更新颜色(用于主题适配)
+ ///
+ private static Pen ClonePenForTheme(Pen source, Color newColor)
+ {
+ var clonedBrush = CloneBrushForTheme(source.Brush, newColor);
+ return new Pen(clonedBrush, source.Thickness)
+ {
+ StartLineCap = source.StartLineCap,
+ EndLineCap = source.EndLineCap,
+ LineJoin = source.LineJoin,
+ MiterLimit = source.MiterLimit
+ };
+ }
+
+ ///
+ /// 应用主题到整个控件树
+ ///
+ public static void ApplyThemeToControl(System.Windows.DependencyObject control)
+ {
+ UpdateTextBlockColors(control);
+ UpdateBorderColors(control);
+ UpdateLineColors(control);
+ UpdateInputControlsColors(control);
+ UpdateButtonColors(control);
+ UpdateImageIconColors(control);
+ }
+ }
+}
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml
index 2196d131..f05c2832 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml
@@ -36,13 +36,13 @@
-
+
-
+
-
+
@@ -58,7 +58,7 @@
-
+
@@ -76,7 +76,8 @@
Style="{StaticResource ComboBoxStyle}"
ItemContainerStyle="{StaticResource ComboBoxItemStyle}"
HorizontalAlignment="Left"
- Width="200">
+ Width="200"
+ SelectionChanged="ComboBoxSplashScreenStyle_SelectionChanged">
@@ -102,7 +103,8 @@
ItemContainerStyle="{StaticResource ComboBoxItemStyle}"
HorizontalAlignment="Left"
Width="250"
- SelectedIndex="0">
+ SelectedIndex="0"
+ SelectionChanged="ComboBoxFloatingBarImg_SelectionChanged">
@@ -132,7 +134,7 @@
-
+
@@ -143,7 +145,7 @@
-
+
@@ -154,7 +156,7 @@
-
+
@@ -164,7 +166,7 @@
-
+
@@ -178,7 +180,7 @@
-
+
@@ -192,7 +194,7 @@
-
+
@@ -200,7 +202,7 @@
-
+
@@ -208,7 +210,7 @@
-
+
@@ -216,7 +218,7 @@
-
+
@@ -224,7 +226,7 @@
-
+
@@ -232,7 +234,7 @@
-
+
@@ -240,7 +242,7 @@
-
+
@@ -248,7 +250,7 @@
-
+
@@ -256,7 +258,7 @@
-
+
@@ -265,10 +267,10 @@
-
+
-
+
@@ -280,16 +282,16 @@
-
+
-
+
-
+
-
+
@@ -306,7 +308,7 @@
-
+
@@ -326,7 +328,7 @@
-
+
@@ -340,7 +342,7 @@
-
+
@@ -354,7 +356,7 @@
-
+
@@ -369,16 +371,16 @@
-
+
-
+
-
+
-
+
@@ -395,7 +397,7 @@
-
+
@@ -410,10 +412,10 @@
-
+
-
+
@@ -424,7 +426,7 @@
-
+
@@ -438,7 +440,7 @@
-
+
@@ -452,7 +454,7 @@
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs
index 6fdb7358..55b071f4 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs
@@ -1,6 +1,13 @@
+using Ink_Canvas;
+using iNKORE.UI.WPF.Helpers;
using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Media;
+using Hardcodet.Wpf.TaskbarNotification;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -9,13 +16,46 @@ namespace Ink_Canvas.Windows.SettingsViews
///
public partial class ThemePanel : UserControl
{
+ private bool _isLoaded = false;
+
public ThemePanel()
{
InitializeComponent();
+ Loaded += ThemePanel_Loaded;
+ }
+
+ private void ThemePanel_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ // 添加触摸支持
+ EnableTouchSupport();
+ // 应用主题
+ ApplyTheme();
+ _isLoaded = true;
+ }
+
+ ///
+ /// 为面板中的所有交互控件启用触摸支持
+ ///
+ private void EnableTouchSupport()
+ {
+ try
+ {
+ // 延迟执行,确保所有控件都已加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ MainWindowSettingsHelper.EnableTouchSupportForControls(this);
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"ThemePanel 启用触摸支持时出错: {ex.Message}");
+ }
}
public event EventHandler IsTopBarNeedShadowEffect;
public event EventHandler IsTopBarNeedNoShadowEffect;
+ public event EventHandler ThemeChanged;
private void ScrollViewerEx_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
@@ -29,6 +69,740 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 加载设置到UI
+ ///
+ public void LoadSettings()
+ {
+ if (MainWindow.Settings == null || MainWindow.Settings.Appearance == null) return;
+
+ _isLoaded = false;
+
+ try
+ {
+ 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;
+ if (val == 0) val = 1.0;
+ ViewboxFloatingBarScaleTransformValueSlider.Value = val;
+ if (ViewboxFloatingBarScaleTransformValueText != null)
+ {
+ ViewboxFloatingBarScaleTransformValueText.Text = val.ToString("F2");
+ }
+ }
+
+ // 浮动工具栏透明度
+ if (ViewboxFloatingBarOpacityValueSlider != null)
+ {
+ ViewboxFloatingBarOpacityValueSlider.Value = appearance.ViewboxFloatingBarOpacityValue;
+ if (ViewboxFloatingBarOpacityValueText != null)
+ {
+ ViewboxFloatingBarOpacityValueText.Text = appearance.ViewboxFloatingBarOpacityValue.ToString("F2");
+ }
+ }
+
+ // 浮栏在PPT下透明度
+ if (ViewboxFloatingBarOpacityInPPTValueSlider != null)
+ {
+ ViewboxFloatingBarOpacityInPPTValueSlider.Value = appearance.ViewboxFloatingBarOpacityInPPTValue;
+ if (ViewboxFloatingBarOpacityInPPTValueText != null)
+ {
+ ViewboxFloatingBarOpacityInPPTValueText.Text = appearance.ViewboxFloatingBarOpacityInPPTValue.ToString("F2");
+ }
+ }
+
+ // 在调色盘窗口中显示笔尖模式按钮
+ 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;
+ if (CheckBoxShowClearButton != null) CheckBoxShowClearButton.IsChecked = appearance.IsShowClearButton;
+ if (CheckBoxShowWhiteboardButton != null) CheckBoxShowWhiteboardButton.IsChecked = appearance.IsShowWhiteboardButton;
+ if (CheckBoxShowHideButton != null) CheckBoxShowHideButton.IsChecked = appearance.IsShowHideButton;
+ if (CheckBoxShowQuickColorPalette != null) CheckBoxShowQuickColorPalette.IsChecked = appearance.IsShowQuickColorPalette;
+ 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}");
+ }
+
+ _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));
+ 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;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ bool isOn = border.Background.ToString() == "#FF3584E4";
+ bool newState = !isOn;
+ SetToggleSwitchState(border, newState);
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ var appearance = MainWindow.Settings.Appearance;
+ if (appearance == null) return;
+
+ switch (tag)
+ {
+ case "EnableSplashScreen":
+ // 调用 MainWindow 中的方法(带主题检查)
+ MainWindowSettingsHelper.InvokeToggleSwitchToggledWithThemeCheck("ToggleSwitchEnableSplashScreen", newState);
+ // 更新UI状态
+ if (SplashScreenStylePanel != null)
+ {
+ SplashScreenStylePanel.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
+ }
+ 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)
+ {
+ taskbar.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
+ }
+ 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);
+ }
+ }
+
+ private void ComboBoxFloatingBarImg_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ 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;
+ if (ViewboxFloatingBarScaleTransformValueSlider != null && ViewboxFloatingBarScaleTransformValueText != null)
+ {
+ double val = ViewboxFloatingBarScaleTransformValueSlider.Value;
+ ViewboxFloatingBarScaleTransformValueText.Text = val.ToString("F2");
+ // 调用 MainWindow 中的方法(会自动检查主题更新)
+ MainWindowSettingsHelper.InvokeSliderValueChanged("ViewboxFloatingBarScaleTransformValueSlider", val);
+ }
+ }
+
+ private void ViewboxFloatingBarOpacityValueSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (ViewboxFloatingBarOpacityValueSlider != null && ViewboxFloatingBarOpacityValueText != null)
+ {
+ double val = ViewboxFloatingBarOpacityValueSlider.Value;
+ ViewboxFloatingBarOpacityValueText.Text = val.ToString("F2");
+ // 调用 MainWindow 中的方法(会自动检查主题更新)
+ MainWindowSettingsHelper.InvokeSliderValueChanged("ViewboxFloatingBarOpacityValueSlider", val);
+ }
+ }
+
+ private void ViewboxFloatingBarOpacityInPPTValueSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ if (ViewboxFloatingBarOpacityInPPTValueSlider != null && ViewboxFloatingBarOpacityInPPTValueText != null)
+ {
+ 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;
+
+ var checkBox = sender as CheckBox;
+ if (checkBox == null) return;
+
+ string name = checkBox.Name;
+ var appearance = MainWindow.Settings.Appearance;
+ if (appearance == null) return;
+
+ 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
+ {
+ { "Theme", new[] { "Light", "Dark", "System" } },
+ { "ChickenSoupSource", new[] { "Osu", "Motivational", "Gaokao", "Hitokoto" } },
+ { "UnFoldBtnImg", new[] { "Arrow", "Pen" } },
+ { "QuickColorPaletteDisplayMode", new[] { "Single", "Double" } },
+ { "EraserDisplayOption", new[] { "Both", "Area", "Line", "None" } }
+ };
+
+ if (!buttons.ContainsKey(group)) return;
+
+ string[] buttonNames = buttons[group];
+
+ for (int i = 0; i < buttonNames.Length; i++)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ ///
+ /// 选项按钮点击事件处理
+ ///
+ private void OptionButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ string[] parts = tag.Split('_');
+ if (parts.Length < 2) return;
+
+ string group = parts[0];
+ string value = parts[1];
+
+ // 清除同组其他按钮的选中状态
+ var parent = border.Parent as Panel;
+ if (parent != null)
+ {
+ foreach (var child in parent.Children)
+ {
+ if (child is Border childBorder && childBorder != border)
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ // 设置当前按钮为选中状态
+ 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;
+
+ switch (group)
+ {
+ case "Theme":
+ // 通过 MainWindowSettingsHelper 调用 ComboBoxTheme 的 SelectionChanged 事件处理器
+ try
+ {
+ var mainWindow = Application.Current.MainWindow as MainWindow;
+ if (mainWindow != null)
+ {
+ 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;
+ }
+
+ if (comboBox.Items.Count > themeIndex)
+ {
+ var selectedItem = comboBox.Items[themeIndex];
+ 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)
+ {
+ case "Light":
+ themeIndex = 0;
+ break;
+ case "Dark":
+ themeIndex = 1;
+ break;
+ case "System":
+ themeIndex = 2;
+ break;
+ default:
+ themeIndex = 2;
+ break;
+ }
+ MainWindowSettingsHelper.UpdateSettingSafely(() =>
+ {
+ appearance.Theme = themeIndex;
+ }, "ComboBoxTheme_SelectionChanged", "ComboBoxTheme");
+ MainWindowSettingsHelper.NotifyThemeUpdateIfNeeded("ComboBoxTheme");
+
+ // 触发主题变化事件,通知设置窗口更新主题
+ ThemeChanged?.Invoke(this, new RoutedEventArgs());
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"切换主题时出错: {ex.Message}");
+ }
+ break;
+
+ case "ChickenSoupSource":
+ int sourceIndex;
+ switch (value)
+ {
+ case "Osu":
+ sourceIndex = 0;
+ break;
+ case "Motivational":
+ sourceIndex = 1;
+ break;
+ case "Gaokao":
+ sourceIndex = 2;
+ break;
+ case "Hitokoto":
+ sourceIndex = 3;
+ break;
+ default:
+ sourceIndex = 3;
+ break;
+ }
+ // 调用 MainWindow 中的方法
+ var mainWindow6 = Application.Current.MainWindow as MainWindow;
+ if (mainWindow6 != null)
+ {
+ var comboBox = mainWindow6.FindName("ComboBoxChickenSoupSource") as System.Windows.Controls.ComboBox;
+ if (comboBox != null && comboBox.Items.Count > sourceIndex)
+ {
+ comboBox.SelectedIndex = sourceIndex;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxChickenSoupSource", comboBox.Items[sourceIndex]);
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ appearance.ChickenSoupSource = sourceIndex;
+ }, "ComboBoxChickenSoupSource");
+ }
+ }
+ break;
+
+ case "UnFoldBtnImg":
+ int imgType;
+ switch (value)
+ {
+ case "Arrow":
+ imgType = 0;
+ break;
+ case "Pen":
+ imgType = 1;
+ break;
+ default:
+ imgType = 0;
+ break;
+ }
+ // 调用 MainWindow 中的方法(带主题检查)
+ var mainWindow3 = Application.Current.MainWindow as MainWindow;
+ if (mainWindow3 != null)
+ {
+ var comboBox = mainWindow3.FindName("ComboBoxUnFoldBtnImg") as System.Windows.Controls.ComboBox;
+ if (comboBox != null && comboBox.Items.Count > imgType)
+ {
+ comboBox.SelectedIndex = imgType;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChangedWithThemeCheck("ComboBoxUnFoldBtnImg", comboBox.Items[imgType]);
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置并通知主题更新
+ MainWindowSettingsHelper.UpdateSettingSafely(() =>
+ {
+ appearance.UnFoldButtonImageType = imgType;
+ }, "ComboBoxUnFoldBtnImg_SelectionChanged", "ComboBoxUnFoldBtnImg");
+ MainWindowSettingsHelper.NotifyThemeUpdateIfNeeded("ComboBoxUnFoldBtnImg");
+ }
+ }
+ break;
+
+ case "QuickColorPaletteDisplayMode":
+ int displayMode;
+ switch (value)
+ {
+ case "Single":
+ displayMode = 0;
+ break;
+ case "Double":
+ displayMode = 1;
+ break;
+ default:
+ displayMode = 1;
+ break;
+ }
+ // 调用 MainWindow 中的方法
+ var mainWindow4 = Application.Current.MainWindow as MainWindow;
+ if (mainWindow4 != null)
+ {
+ var comboBox = mainWindow4.FindName("ComboBoxQuickColorPaletteDisplayMode") as System.Windows.Controls.ComboBox;
+ if (comboBox != null && comboBox.Items.Count > displayMode)
+ {
+ comboBox.SelectedIndex = displayMode;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxQuickColorPaletteDisplayMode", comboBox.Items[displayMode]);
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ appearance.QuickColorPaletteDisplayMode = displayMode;
+ }, "ComboBoxQuickColorPaletteDisplayMode");
+ }
+ }
+ break;
+
+ case "EraserDisplayOption":
+ int eraserOption;
+ switch (value)
+ {
+ case "Both":
+ eraserOption = 0;
+ break;
+ case "Area":
+ eraserOption = 1;
+ break;
+ case "Line":
+ eraserOption = 2;
+ break;
+ case "None":
+ eraserOption = 3;
+ break;
+ default:
+ eraserOption = 0;
+ break;
+ }
+ // 调用 MainWindow 中的方法
+ var mainWindow5 = Application.Current.MainWindow as MainWindow;
+ if (mainWindow5 != null)
+ {
+ var comboBox = mainWindow5.FindName("ComboBoxEraserDisplayOption") as System.Windows.Controls.ComboBox;
+ if (comboBox != null && comboBox.Items.Count > eraserOption)
+ {
+ comboBox.SelectedIndex = eraserOption;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("ComboBoxEraserDisplayOption", comboBox.Items[eraserOption]);
+ }
+ else
+ {
+ // 如果找不到控件,直接更新设置
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ appearance.EraserDisplayOption = eraserOption;
+ }, "ComboBoxEraserDisplayOption");
+ }
+ }
+ break;
+ }
+ }
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ 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 0ce9307f..1d0ee8c6 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/TimerPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/TimerPanel.xaml.cs
@@ -29,6 +29,21 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ ThemeHelper.ApplyThemeToControl(this);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"TimerPanel 应用主题时出错: {ex.Message}");
+ }
+ }
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml
index 1a6aba6b..a7a0a7d0 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml
@@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:settingsViews="clr-namespace:Ink_Canvas.Windows.SettingsViews"
WindowStartupLocation="CenterScreen" d:DesignHeight="19198"
mc:Ignorable="d" WindowStyle="None" ResizeMode="CanMinimize" Background="Transparent"
@@ -91,11 +92,39 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -174,6 +203,102 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -493,13 +618,13 @@
-
+
-
+
-
+
@@ -512,8 +637,8 @@
-
-
+
+
@@ -525,6 +650,70 @@
+
+
+
+
+
+
+
+
+
@@ -536,14 +725,14 @@
-
+
-
+
@@ -629,11 +818,11 @@
-
+
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs
index 514bf164..c66b303b 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs
@@ -1,4 +1,5 @@
using iNKORE.UI.WPF.Helpers;
+using Ink_Canvas.Windows.SettingsViews;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -14,14 +15,27 @@ namespace Ink_Canvas.Windows
{
public partial class SettingsWindow : Window
{
+ private MainWindow _mainWindow;
public SettingsWindow()
{
InitializeComponent();
+ // 获取 MainWindow 实例
+ _mainWindow = Application.Current.MainWindow as MainWindow;
+
// 初始化搜索面板事件
SearchPanelControl.NavigateToItem += SearchPanel_NavigateToItem;
SearchPanelControl.CloseSearch += SearchPanel_CloseSearch;
+
+ // 订阅菜单关闭事件,确保状态同步
+ if (MenuButtonContextMenu != null)
+ {
+ MenuButtonContextMenu.Closed += (s, e) =>
+ {
+ // 菜单关闭时的处理
+ };
+ }
// 初始化侧边栏项目
SidebarItemsControl.ItemsSource = SidebarItems;
@@ -74,7 +88,7 @@ namespace Ink_Canvas.Windows
Type = SidebarItemType.Item,
Title = "快捷键设置",
Name = "ShortcutsItem",
- IconSource = FindResource("AppearanceIcon") as DrawingImage,
+ IconSource = FindResource("ShortcutsIcon") as DrawingImage,
Selected = false,
});
SidebarItems.Add(new SidebarItem()
@@ -82,7 +96,7 @@ namespace Ink_Canvas.Windows
Type = SidebarItemType.Item,
Title = "崩溃处理",
Name = "CrashActionItem",
- IconSource = FindResource("AppearanceIcon") as DrawingImage,
+ IconSource = FindResource("CrashActionIcon") as DrawingImage,
Selected = false,
});
SidebarItems.Add(new SidebarItem()
@@ -240,6 +254,13 @@ namespace Ink_Canvas.Windows
PowerPointPanel.IsTopBarNeedNoShadowEffect += (o, s) => DropShadowEffectTopBar.Opacity = 0;
ThemePanel.IsTopBarNeedShadowEffect += (o, s) => DropShadowEffectTopBar.Opacity = 0.25;
ThemePanel.IsTopBarNeedNoShadowEffect += (o, s) => DropShadowEffectTopBar.Opacity = 0;
+
+ // 监听主题变化
+ ThemePanel.ThemeChanged += (o, s) =>
+ {
+ ApplyTheme();
+ ApplyThemeToAllPanels();
+ };
ShortcutsPanel.IsTopBarNeedShadowEffect += (o, s) => DropShadowEffectTopBar.Opacity = 0.25;
ShortcutsPanel.IsTopBarNeedNoShadowEffect += (o, s) => DropShadowEffectTopBar.Opacity = 0;
CrashActionPanel.IsTopBarNeedShadowEffect += (o, s) => DropShadowEffectTopBar.Opacity = 0.25;
@@ -253,11 +274,564 @@ namespace Ink_Canvas.Windows
AdvancedPanel.IsTopBarNeedShadowEffect += (o, s) => DropShadowEffectTopBar.Opacity = 0.25;
AdvancedPanel.IsTopBarNeedNoShadowEffect += (o, s) => DropShadowEffectTopBar.Opacity = 0;
- _selectedSidebarItemName = "CanvasAndInkItem";
+ _selectedSidebarItemName = "StartupItem";
+
+ // 初始化侧边栏项目的主题状态
+ bool isDarkTheme = MainWindow.Settings?.Appearance != null &&
+ (MainWindow.Settings.Appearance.Theme == 1 ||
+ (MainWindow.Settings.Appearance.Theme == 2 && !IsSystemThemeLight()));
+ foreach (var item in SidebarItems)
+ {
+ item.IsDarkTheme = isDarkTheme;
+ }
+
UpdateSidebarItemsSelection();
// 为自定义滑块控件添加触摸支持
AddTouchSupportToCustomSliders();
+
+ // 先应用主题,确保标题栏等元素正确显示
+ ApplyTheme();
+
+ // 加载所有面板的设置
+ LoadAllPanelsSettings();
+
+ // 通知所有面板应用主题
+ ApplyThemeToAllPanels();
+
+ // 延迟再次应用主题,确保所有元素都正确应用主题(特别是标题栏)
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ ApplyTheme();
+ ApplyThemeToAllPanels();
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+
+ ///
+ /// 通知所有面板应用主题
+ ///
+ private void ApplyThemeToAllPanels()
+ {
+ try
+ {
+ bool isDarkTheme = MainWindow.Settings?.Appearance != null &&
+ (MainWindow.Settings.Appearance.Theme == 1 ||
+ (MainWindow.Settings.Appearance.Theme == 2 && !IsSystemThemeLight()));
+
+ // 使用反射调用所有面板的 ApplyTheme 方法(如果存在)
+ var panels = new UserControl[]
+ {
+ StartupPanel, CanvasAndInkPanel, GesturesPanel, InkRecognitionPanel,
+ ThemePanel, ShortcutsPanel, CrashActionPanel, PowerPointPanel,
+ AutomationPanel, LuckyRandomPanel, StoragePanel, SnapshotPanel,
+ AdvancedPanel, SettingsAboutPanel, AppearancePanel, SearchPanelControl
+ };
+
+ foreach (var panel in panels)
+ {
+ if (panel != null)
+ {
+ var method = panel.GetType().GetMethod("ApplyTheme",
+ System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
+ if (method != null)
+ {
+ try
+ {
+ method.Invoke(panel, null);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"应用主题到 {panel.GetType().Name} 时出错: {ex.Message}");
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"通知面板应用主题时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 应用主题
+ ///
+ public void ApplyTheme()
+ {
+ try
+ {
+ if (MainWindow.Settings?.Appearance == null) return;
+
+ bool isDarkTheme = MainWindow.Settings.Appearance.Theme == 1 ||
+ (MainWindow.Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
+
+ if (isDarkTheme)
+ {
+ // 深色主题 - 参考 Windows 系统设置
+ if (MainBorder != null)
+ {
+ MainBorder.Background = ThemeHelper.GetBackgroundPrimaryBrush(); // Windows 系统主背景 #202020
+ MainBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(0, 120, 215)); // Windows 系统强调色(蓝色)
+ }
+ if (SidebarBorder != null)
+ {
+ SidebarBorder.Background = ThemeHelper.GetBackgroundSecondaryBrush(); // Windows 系统次要背景 #191919
+ SidebarBorder.BorderBrush = ThemeHelper.GetBorderPrimaryBrush(); // Windows 系统边框
+ }
+ if (SearchButtonBorder != null)
+ {
+ SearchButtonBorder.Background = ThemeHelper.GetButtonBackgroundBrush(); // Windows 系统按钮背景
+ // 更新搜索按钮图标颜色
+ UpdateButtonIconColor(SearchButtonBorder, true);
+ }
+ if (MenuButtonBorder != null)
+ {
+ MenuButtonBorder.Background = ThemeHelper.GetButtonBackgroundBrush(); // Windows 系统按钮背景
+ // 更新菜单按钮图标颜色
+ UpdateButtonIconColor(MenuButtonBorder, true);
+ }
+ if (TitleTextBlock != null)
+ {
+ TitleTextBlock.Foreground = ThemeHelper.GetTextPrimaryBrush(); // Windows 系统主文字颜色
+ }
+ if (MenuButtonContextMenu != null)
+ {
+ MenuButtonContextMenu.Background = ThemeHelper.GetBackgroundSecondaryBrush(); // Windows 系统菜单背景
+ MenuButtonContextMenu.BorderBrush = ThemeHelper.GetBorderPrimaryBrush(); // Windows 系统边框
+ // 更新上下文菜单中的图标和文字颜色
+ UpdateContextMenuTheme(MenuButtonContextMenu, true);
+ }
+ if (SettingsWindowTitle != null)
+ {
+ SettingsWindowTitle.Foreground = ThemeHelper.GetTextPrimaryBrush(); // Windows 系统主文字颜色
+ }
+ if (TopBarBorder != null)
+ {
+ TopBarBorder.Background = ThemeHelper.GetBackgroundPrimaryBrush(); // Windows 系统主背景
+ }
+ // 更新内部标题栏背景 - 使用直接访问而不是 FindDescendantByName
+ // TopBarBackgroundBorder 是 TopBarBorder 的直接子元素
+ if (TopBarBorder != null && TopBarBorder.Child is Border topBarBackgroundBorder)
+ {
+ topBarBackgroundBorder.Background = ThemeHelper.GetBackgroundPrimaryBrush(); // Windows 系统主背景
+ }
+ // 如果上面的方法找不到,尝试使用 FindDescendantByName 作为备用
+ var topBarBackgroundBorderFallback = this.FindDescendantByName("TopBarBackgroundBorder") as Border;
+ if (topBarBackgroundBorderFallback != null)
+ {
+ topBarBackgroundBorderFallback.Background = ThemeHelper.GetBackgroundPrimaryBrush(); // Windows 系统主背景
+ }
+
+ // 更新侧边栏项目文本颜色
+ foreach (var item in SidebarItems)
+ {
+ // 通过反射或直接访问来更新文本颜色
+ // 这里需要在 XAML 中绑定或通过其他方式更新
+ }
+
+ // 更新滚动条样式 - 参考 Windows 系统设置
+ var scrollBarTrack = this.FindDescendantByName("ScrollBarBorderTrackBackground") as Border;
+ if (scrollBarTrack != null)
+ {
+ scrollBarTrack.Background = ThemeHelper.GetScrollBarTrackBrush(); // Windows 系统滚动条轨道
+ scrollBarTrack.Opacity = 0.3;
+ }
+
+ // 更新侧边栏项目主题
+ foreach (var item in SidebarItems)
+ {
+ item.IsDarkTheme = true;
+ }
+ CollectionViewSource.GetDefaultView(SidebarItems).Refresh();
+
+ // 更新图标颜色
+ UpdateIconColors(true);
+ }
+ else
+ {
+ // 浅色主题(默认)
+ if (MainBorder != null)
+ {
+ MainBorder.Background = new SolidColorBrush(Color.FromRgb(250, 250, 250));
+ MainBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(53, 132, 228));
+ }
+ if (SidebarBorder != null)
+ {
+ SidebarBorder.Background = new SolidColorBrush(Color.FromRgb(235, 235, 235));
+ SidebarBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ }
+ if (SearchButtonBorder != null)
+ {
+ SearchButtonBorder.Background = new SolidColorBrush(Color.FromRgb(217, 217, 217));
+ // 更新搜索按钮图标颜色
+ UpdateButtonIconColor(SearchButtonBorder, false);
+ }
+ if (MenuButtonBorder != null)
+ {
+ MenuButtonBorder.Background = new SolidColorBrush(Color.FromRgb(217, 217, 217));
+ // 更新菜单按钮图标颜色
+ UpdateButtonIconColor(MenuButtonBorder, false);
+ }
+ if (TitleTextBlock != null)
+ {
+ TitleTextBlock.Foreground = new SolidColorBrush(Color.FromRgb(46, 52, 54));
+ }
+ if (MenuButtonContextMenu != null)
+ {
+ MenuButtonContextMenu.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
+ MenuButtonContextMenu.BorderBrush = new SolidColorBrush(Color.FromRgb(211, 211, 211));
+ // 更新上下文菜单中的图标和文字颜色
+ UpdateContextMenuTheme(MenuButtonContextMenu, false);
+ }
+ if (SettingsWindowTitle != null)
+ {
+ SettingsWindowTitle.Foreground = new SolidColorBrush(Color.FromRgb(46, 52, 54));
+ }
+ if (TopBarBorder != null)
+ {
+ TopBarBorder.Background = new SolidColorBrush(Color.FromRgb(250, 250, 250));
+ }
+ // 更新内部标题栏背景 - 使用直接访问而不是 FindDescendantByName
+ // TopBarBackgroundBorder 是 TopBarBorder 的直接子元素
+ if (TopBarBorder != null && TopBarBorder.Child is Border topBarBackgroundBorder)
+ {
+ topBarBackgroundBorder.Background = new SolidColorBrush(Color.FromRgb(250, 250, 250));
+ }
+ // 如果上面的方法找不到,尝试使用 FindDescendantByName 作为备用
+ var topBarBackgroundBorderFallback = this.FindDescendantByName("TopBarBackgroundBorder") as Border;
+ if (topBarBackgroundBorderFallback != null)
+ {
+ topBarBackgroundBorderFallback.Background = new SolidColorBrush(Color.FromRgb(250, 250, 250));
+ }
+
+ // 更新滚动条样式
+ var scrollBarTrack = this.FindDescendantByName("ScrollBarBorderTrackBackground") as Border;
+ if (scrollBarTrack != null)
+ {
+ scrollBarTrack.Background = ThemeHelper.GetScrollBarTrackBrush(); // Windows 系统滚动条轨道
+ scrollBarTrack.Opacity = 0;
+ }
+
+ // 更新侧边栏项目主题
+ foreach (var item in SidebarItems)
+ {
+ item.IsDarkTheme = false;
+ }
+ CollectionViewSource.GetDefaultView(SidebarItems).Refresh();
+
+ // 更新图标颜色
+ UpdateIconColors(false);
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"应用主题时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 更新所有图标颜色以适配主题
+ ///
+ private void UpdateIconColors(bool isDarkTheme)
+ {
+ try
+ {
+ // 根据主题选择颜色
+ Color iconColor = isDarkTheme
+ ? Color.FromRgb(243, 243, 243) // 深色主题使用浅色图标 #F3F3F3
+ : Color.FromRgb(34, 34, 34); // 浅色主题使用深色图标 #222222
+
+ // 更新每个侧边栏项目的图标
+ foreach (var item in SidebarItems)
+ {
+ if (item.IconSource is DrawingImage drawingImage &&
+ drawingImage.Drawing is DrawingGroup drawingGroup)
+ {
+ // 克隆并更新图标
+ var clonedDrawing = CloneDrawingGroup(drawingGroup, iconColor);
+ item.IconSource = new DrawingImage { Drawing = clonedDrawing };
+ }
+ }
+
+ CollectionViewSource.GetDefaultView(SidebarItems).Refresh();
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"更新图标颜色时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 克隆 DrawingGroup 并更新颜色
+ ///
+ private DrawingGroup CloneDrawingGroup(DrawingGroup source, Color newColor)
+ {
+ var cloned = new DrawingGroup();
+ cloned.ClipGeometry = source.ClipGeometry?.Clone();
+ cloned.Opacity = source.Opacity;
+ cloned.Transform = source.Transform?.Clone();
+
+ foreach (var drawing in source.Children)
+ {
+ if (drawing is GeometryDrawing geometryDrawing)
+ {
+ var clonedGeometry = geometryDrawing.Geometry?.Clone();
+ var clonedBrush = CloneBrush(geometryDrawing.Brush, newColor);
+ var clonedPen = geometryDrawing.Pen != null
+ ? ClonePen(geometryDrawing.Pen, newColor)
+ : null;
+
+ cloned.Children.Add(new GeometryDrawing(clonedBrush, clonedPen, clonedGeometry));
+ }
+ else if (drawing is DrawingGroup subGroup)
+ {
+ cloned.Children.Add(CloneDrawingGroup(subGroup, newColor));
+ }
+ else
+ {
+ // 对于其他类型的 Drawing,尝试克隆
+ cloned.Children.Add(drawing);
+ }
+ }
+
+ return cloned;
+ }
+
+ ///
+ /// 克隆 Brush 并更新颜色
+ ///
+ private Brush CloneBrush(Brush source, Color newColor)
+ {
+ if (source is SolidColorBrush solidBrush)
+ {
+ // 检查是否是深色(需要更新的颜色)
+ var originalColor = solidBrush.Color;
+ if (originalColor.R == 34 && originalColor.G == 34 && originalColor.B == 34) // #222222
+ {
+ return new SolidColorBrush(newColor) { Opacity = solidBrush.Opacity };
+ }
+ else if (originalColor.A > 0 && originalColor != Colors.Transparent &&
+ originalColor.R < 50 && originalColor.G < 50 && originalColor.B < 50) // 深色
+ {
+ return new SolidColorBrush(newColor) { Opacity = solidBrush.Opacity };
+ }
+ // 保持其他颜色不变(如透明色)
+ return new SolidColorBrush(originalColor) { Opacity = solidBrush.Opacity };
+ }
+ return source?.Clone();
+ }
+
+ ///
+ /// 克隆 Pen 并更新颜色
+ ///
+ private Pen ClonePen(Pen source, Color newColor)
+ {
+ var clonedBrush = CloneBrush(source.Brush, newColor);
+ return new Pen(clonedBrush, source.Thickness)
+ {
+ StartLineCap = source.StartLineCap,
+ EndLineCap = source.EndLineCap,
+ LineJoin = source.LineJoin,
+ MiterLimit = source.MiterLimit
+ };
+ }
+
+ ///
+ /// 更新上下文菜单的主题(图标和文字颜色)
+ ///
+ private void UpdateContextMenuTheme(ContextMenu contextMenu, bool isDarkTheme)
+ {
+ try
+ {
+ Color iconColor = isDarkTheme
+ ? Color.FromRgb(243, 243, 243) // 深色主题使用浅色图标 #F3F3F3
+ : Color.FromRgb(34, 34, 34); // 浅色主题使用深色图标 #222222
+
+ foreach (var item in contextMenu.Items)
+ {
+ if (item is MenuItem menuItem)
+ {
+ // 更新文字颜色
+ menuItem.Foreground = ThemeHelper.GetTextPrimaryBrush();
+
+ // 更新图标颜色
+ if (menuItem.Icon is Image iconImage && iconImage.Source is DrawingImage drawingImage)
+ {
+ if (drawingImage.Drawing is DrawingGroup drawingGroup)
+ {
+ var clonedDrawing = CloneDrawingGroup(drawingGroup, iconColor);
+ iconImage.Source = new DrawingImage { Drawing = clonedDrawing };
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"更新上下文菜单主题时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 更新按钮中的图标颜色
+ ///
+ private void UpdateButtonIconColor(Border buttonBorder, bool isDarkTheme)
+ {
+ try
+ {
+ Color iconColor = isDarkTheme
+ ? Color.FromRgb(243, 243, 243) // 深色主题使用浅色图标 #F3F3F3
+ : Color.FromRgb(34, 34, 34); // 浅色主题使用深色图标 #222222
+
+ // 查找按钮中的 Image 控件
+ var image = FindVisualChild(buttonBorder);
+ if (image != null && image.Source is DrawingImage drawingImage)
+ {
+ if (drawingImage.Drawing is DrawingGroup drawingGroup)
+ {
+ var clonedDrawing = CloneDrawingGroup(drawingGroup, iconColor);
+ image.Source = new DrawingImage { Drawing = clonedDrawing };
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"更新按钮图标颜色时出错: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 在视觉树中查找指定类型的子元素
+ ///
+ private T FindVisualChild(DependencyObject parent) where T : DependencyObject
+ {
+ for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
+ {
+ var child = VisualTreeHelper.GetChild(parent, i);
+ if (child is T result)
+ {
+ return result;
+ }
+ var childOfChild = FindVisualChild(child);
+ if (childOfChild != null)
+ {
+ return childOfChild;
+ }
+ }
+ return null;
+ }
+
+ ///
+ /// 检查系统主题是否为浅色
+ ///
+ private bool IsSystemThemeLight()
+ {
+ try
+ {
+ var registryKey = Microsoft.Win32.Registry.CurrentUser;
+ var themeKey = registryKey.OpenSubKey("software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
+ var keyValue = 0;
+ if (themeKey != null) keyValue = (int)themeKey.GetValue("SystemUsesLightTheme");
+ return keyValue == 1;
+ }
+ catch
+ {
+ return true; // 默认返回浅色主题
+ }
+ }
+
+ ///
+ /// 加载所有设置面板的设置
+ ///
+ private void LoadAllPanelsSettings()
+ {
+ try
+ {
+ // 预加载所有面板,确保它们在显示前都已初始化
+ // 使用 Dispatcher.BeginInvoke 延迟执行,确保所有面板都已创建
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ try
+ {
+ // 所有设置面板列表
+ var allPanels = new UserControl[]
+ {
+ StartupPanel,
+ CanvasAndInkPanel,
+ GesturesPanel,
+ InkRecognitionPanel,
+ ThemePanel,
+ ShortcutsPanel,
+ CrashActionPanel,
+ PowerPointPanel,
+ AutomationPanel,
+ LuckyRandomPanel,
+ StoragePanel,
+ SnapshotPanel,
+ AdvancedPanel,
+ SettingsAboutPanel,
+ AppearancePanel
+ };
+
+ // 预加载所有面板:调用 LoadSettings、EnableTouchSupport 和 ApplyTheme
+ foreach (var panel in allPanels)
+ {
+ if (panel != null)
+ {
+ try
+ {
+ // 直接调用 LoadSettings 确保设置被加载
+ var loadSettingsMethod = panel.GetType().GetMethod("LoadSettings",
+ System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
+ if (loadSettingsMethod != null)
+ {
+ loadSettingsMethod.Invoke(panel, null);
+ }
+
+ // 调用 EnableTouchSupport 确保触摸支持已启用
+ var enableTouchSupportMethod = panel.GetType().GetMethod("EnableTouchSupport",
+ System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
+ if (enableTouchSupportMethod != null)
+ {
+ enableTouchSupportMethod.Invoke(panel, null);
+ }
+ else
+ {
+ // 如果面板没有 EnableTouchSupport 方法,直接使用 MainWindowSettingsHelper
+ MainWindowSettingsHelper.EnableTouchSupportForControls(panel);
+ }
+
+ // 调用 ApplyTheme 确保主题已应用
+ var applyThemeMethod = panel.GetType().GetMethod("ApplyTheme",
+ System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
+ if (applyThemeMethod != null)
+ {
+ applyThemeMethod.Invoke(panel, null);
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"预加载面板 {panel?.GetType().Name} 时出错: {ex.Message}");
+ }
+ }
+ }
+
+ // 再次应用主题到所有面板,确保主题完全加载
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ ApplyThemeToAllPanels();
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"预加载所有面板时出错: {ex.Message}");
+ }
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"加载设置面板设置时出错: {ex.Message}");
+ }
}
@@ -268,13 +842,37 @@ namespace Ink_Canvas.Windows
Separator
}
- public class SidebarItem
+ public class SidebarItem : System.ComponentModel.INotifyPropertyChanged
{
public SidebarItemType Type { get; set; }
public string Title { get; set; }
public string Name { get; set; }
public ImageSource IconSource { get; set; }
- public bool Selected { get; set; }
+ private bool _selected = false;
+ private bool _isDarkTheme = false;
+
+ public bool Selected
+ {
+ get => _selected;
+ set
+ {
+ _selected = value;
+ OnPropertyChanged(nameof(_siBackground));
+ }
+ }
+
+ public bool IsDarkTheme
+ {
+ get => _isDarkTheme;
+ set
+ {
+ _isDarkTheme = value;
+ OnPropertyChanged(nameof(_siForeground));
+ OnPropertyChanged(nameof(_siBackground));
+ OnPropertyChanged(nameof(_spStroke));
+ }
+ }
+
public Visibility _spVisibility
{
get => Type == SidebarItemType.Separator ? Visibility.Visible : Visibility.Collapsed;
@@ -286,9 +884,36 @@ namespace Ink_Canvas.Windows
public SolidColorBrush _siBackground
{
- get => Selected
- ? new SolidColorBrush(Color.FromRgb(217, 217, 217))
- : new SolidColorBrush(Colors.Transparent);
+ get
+ {
+ if (Selected)
+ {
+ return _isDarkTheme
+ ? ThemeHelper.GetSelectedBackgroundBrush() // Windows 系统选中背景 #3E3E3E
+ : new SolidColorBrush(Color.FromRgb(237, 237, 237));
+ }
+ return new SolidColorBrush(Colors.Transparent);
+ }
+ }
+
+ public SolidColorBrush _siForeground
+ {
+ get => _isDarkTheme
+ ? ThemeHelper.GetTextPrimaryBrush() // Windows 系统主文字颜色 #F3F3F3
+ : new SolidColorBrush(Color.FromRgb(0, 0, 0));
+ }
+
+ public SolidColorBrush _spStroke
+ {
+ get => _isDarkTheme
+ ? ThemeHelper.GetSeparatorBrush() // Windows 系统分隔线 #3E3E3E
+ : new SolidColorBrush(Color.FromRgb(237, 237, 237));
+ }
+
+ public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
+ protected virtual void OnPropertyChanged(string propertyName)
+ {
+ PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
@@ -311,7 +936,37 @@ namespace Ink_Canvas.Windows
}
}
CollectionViewSource.GetDefaultView(SidebarItems).Refresh();
+
+ // 确保主题状态同步
+ bool isDarkTheme = MainWindow.Settings?.Appearance != null &&
+ (MainWindow.Settings.Appearance.Theme == 1 ||
+ (MainWindow.Settings.Appearance.Theme == 2 && !IsSystemThemeLight()));
+ foreach (var si in SidebarItems)
+ {
+ si.IsDarkTheme = isDarkTheme;
+ }
+ // 定义面板映射
+ var panelMappings = new Dictionary
+ {
+ { "AboutItem", SettingsAboutPanel },
+ { "CanvasAndInkItem", CanvasAndInkPanel },
+ { "GesturesItem", GesturesPanel },
+ { "StartupItem", StartupPanel },
+ { "ThemeItem", ThemePanel },
+ { "ShortcutsItem", ShortcutsPanel },
+ { "CrashActionItem", CrashActionPanel },
+ { "InkRecognitionItem", InkRecognitionPanel },
+ { "AutomationItem", AutomationPanel },
+ { "PowerPointItem", PowerPointPanel },
+ { "LuckyRandomItem", LuckyRandomPanel },
+ { "StorageItem", StoragePanel },
+ { "SnapshotItem", SnapshotPanel },
+ { "AdvancedItem", AdvancedPanel },
+ { "AppearanceItem", AppearancePanel }
+ };
+
+ // 设置面板可见性并应用主题
if (AboutPane != null) AboutPane.Visibility = _selectedSidebarItemName == "AboutItem" ? Visibility.Visible : Visibility.Collapsed;
if (CanvasAndInkPane != null) CanvasAndInkPane.Visibility = _selectedSidebarItemName == "CanvasAndInkItem" ? Visibility.Visible : Visibility.Collapsed;
if (GesturesPane != null) GesturesPane.Visibility = _selectedSidebarItemName == "GesturesItem" ? Visibility.Visible : Visibility.Collapsed;
@@ -326,6 +981,31 @@ namespace Ink_Canvas.Windows
if (StoragePane != null) StoragePane.Visibility = _selectedSidebarItemName == "StorageItem" ? Visibility.Visible : Visibility.Collapsed;
if (SnapshotPane != null) SnapshotPane.Visibility = _selectedSidebarItemName == "SnapshotItem" ? Visibility.Visible : Visibility.Collapsed;
if (AdvancedPane != null) AdvancedPane.Visibility = _selectedSidebarItemName == "AdvancedItem" ? Visibility.Visible : Visibility.Collapsed;
+
+ // 为新显示的面板应用主题(延迟执行,确保面板已完全显示)
+ if (panelMappings.ContainsKey(_selectedSidebarItemName))
+ {
+ var selectedPanel = panelMappings[_selectedSidebarItemName];
+ if (selectedPanel != null)
+ {
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ try
+ {
+ var applyThemeMethod = selectedPanel.GetType().GetMethod("ApplyTheme",
+ System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
+ if (applyThemeMethod != null)
+ {
+ applyThemeMethod.Invoke(selectedPanel, null);
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"切换面板时应用主题到 {selectedPanel.GetType().Name} 时出错: {ex.Message}");
+ }
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ }
if (SettingsPaneScrollViewers != null)
{
foreach (var sv in SettingsPaneScrollViewers)
@@ -490,7 +1170,74 @@ namespace Ink_Canvas.Windows
private void MenuButton_Click(object sender, MouseButtonEventArgs e)
{
- // 菜单功能 - 可以显示上下文菜单或选项菜单
+ // 切换上下文菜单的显示状态
+ if (MenuButtonContextMenu != null)
+ {
+ MenuButtonContextMenu.PlacementTarget = MenuButtonBorder;
+ MenuButtonContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
+
+ // 如果菜单已打开,则关闭;如果已关闭,则打开
+ bool isCurrentlyOpen = MenuButtonContextMenu.IsOpen;
+
+ if (isCurrentlyOpen)
+ {
+ // 如果菜单已打开,直接关闭
+ MenuButtonContextMenu.IsOpen = false;
+ }
+ else
+ {
+ // 如果菜单未打开,打开菜单
+ MenuButtonContextMenu.IsOpen = true;
+ }
+
+ // 标记事件已处理,防止菜单拦截点击
+ e.Handled = true;
+ }
+ }
+
+ private void MenuItemExit_Click(object sender, RoutedEventArgs e)
+ {
+ // 关闭设置窗口
+ Close();
+
+ // 调用主窗口的退出方法
+ if (_mainWindow != null)
+ {
+ _mainWindow.BtnExit_Click(sender, e);
+ }
+ }
+
+ private void MenuItemRestart_Click(object sender, RoutedEventArgs e)
+ {
+ // 关闭设置窗口
+ Close();
+
+ // 调用主窗口的重启方法
+ if (_mainWindow != null)
+ {
+ _mainWindow.BtnRestart_Click(sender, e);
+ }
+ }
+
+ private void MenuItemReset_Click(object sender, RoutedEventArgs e)
+ {
+ // 调用主窗口的重置配置方法
+ if (_mainWindow != null)
+ {
+ _mainWindow.BtnResetToSuggestion_Click(sender, e);
+ }
+ }
+
+ private void MenuItemSwitchToOldSettings_Click(object sender, RoutedEventArgs e)
+ {
+ // 关闭新设置窗口
+ Close();
+
+ // 调用主窗口的显示老设置面板方法
+ if (_mainWindow != null)
+ {
+ _mainWindow.ShowOldSettingsPanel();
+ }
}
private void ToggleSwitch_Click(object sender, MouseButtonEventArgs e)