Files
community/Ink Canvas/Windows/SettingsViews/SettingsViews/CanvasAndInkPanel.xaml.cs
T

685 lines
30 KiB
C#
Raw Normal View History

2026-01-02 01:35:22 +08:00
using iNKORE.UI.WPF.Helpers;
2025-12-28 08:48:09 +08:00
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Ink_Canvas.Windows.SettingsViews
{
2026-01-10 17:31:55 +08:00
/// <summary>
/// CanvasAndInkPanel.xaml 的交互逻辑
/// </summary>
2025-12-28 08:48:09 +08:00
public partial class CanvasAndInkPanel : UserControl
{
2026-01-02 01:35:22 +08:00
private bool _isLoaded = false;
2025-12-28 08:48:09 +08:00
public CanvasAndInkPanel()
{
InitializeComponent();
2026-01-02 01:35:22 +08:00
Loaded += CanvasAndInkPanel_Loaded;
}
private void CanvasAndInkPanel_Loaded(object sender, RoutedEventArgs e)
{
LoadSettings();
2026-01-10 17:31:55 +08:00
// 添加触摸支持
2026-01-02 01:35:22 +08:00
EnableTouchSupport();
2026-01-10 17:31:55 +08:00
// 应用主题
2026-01-02 01:35:22 +08:00
ApplyTheme();
_isLoaded = true;
}
2026-01-10 17:31:55 +08:00
/// <summary>
/// 为面板中的所有交互控件启用触摸支持
/// </summary>
2026-01-02 01:35:22 +08:00
private void EnableTouchSupport()
{
try
{
2026-01-10 17:31:55 +08:00
// 延迟执行,确保所有控件都已加载
2026-01-02 01:35:22 +08:00
Dispatcher.BeginInvoke(new Action(() =>
{
MainWindowSettingsHelper.EnableTouchSupportForControls(this);
}), System.Windows.Threading.DispatcherPriority.Loaded);
}
catch (Exception ex)
{
2026-01-10 17:31:55 +08:00
System.Diagnostics.Debug.WriteLine($"CanvasAndInkPanel 启用触摸支持时出错: {ex.Message}");
2026-01-02 01:35:22 +08:00
}
2025-12-28 08:48:09 +08:00
}
public event EventHandler<RoutedEventArgs> IsTopBarNeedShadowEffect;
public event EventHandler<RoutedEventArgs> IsTopBarNeedNoShadowEffect;
private void ScrollViewerEx_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
var scrollViewer = (ScrollViewer)sender;
if (scrollViewer.VerticalOffset >= 10)
{
IsTopBarNeedShadowEffect?.Invoke(this, new RoutedEventArgs());
}
else
{
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
2026-01-02 01:35:22 +08:00
2026-01-10 17:31:55 +08:00
/// <summary>
/// 加载设置到UI
/// </summary>
2026-01-02 01:35:22 +08:00
public void LoadSettings()
{
if (MainWindow.Settings == null || MainWindow.Settings.Canvas == null) return;
_isLoaded = false;
try
{
var canvas = MainWindow.Settings.Canvas;
2026-01-10 17:31:55 +08:00
// 显示画笔光标
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchShowCursor"), canvas.IsShowCursor);
2026-01-10 17:31:55 +08:00
// 启用压感触屏模式
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnablePressureTouchMode"), canvas.EnablePressureTouchMode);
2026-01-10 17:31:55 +08:00
// 屏蔽压感
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchDisablePressure"), canvas.DisablePressure);
2026-01-10 17:31:55 +08:00
// 板擦橡皮大小
2026-01-02 01:35:22 +08:00
SetOptionButtonState("EraserSize", canvas.EraserSize);
2026-01-10 17:31:55 +08:00
// 退出画板模式后隐藏墨迹
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchHideStrokeWhenSelecting"), canvas.HideStrokeWhenSelecting);
2026-01-10 17:31:55 +08:00
// 清空墨迹时删除墨迹历史记录
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchClearCanvasAndClearTimeMachine"), canvas.ClearCanvasAndClearTimeMachine);
2026-01-10 17:31:55 +08:00
// 清空画布时同时清空图片
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchClearCanvasAlsoClearImages"), canvas.ClearCanvasAlsoClearImages);
2026-01-10 17:31:55 +08:00
// 插入图片时自动压缩
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchCompressPicturesUploaded"), canvas.IsCompressPicturesUploaded);
2026-01-10 17:31:55 +08:00
// 保留双曲线渐近线
2026-01-02 01:35:22 +08:00
SetOptionButtonState("HyperbolaAsymptote", (int)canvas.HyperbolaAsymptoteOption);
2026-01-10 17:32:14 +08:00
// 绘制圆时显示圆心位置
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchShowCircleCenter"), canvas.ShowCircleCenter);
// 使用WPF默认贝塞尔曲线平滑
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchFitToCurve"), canvas.FitToCurve && !canvas.UseAdvancedBezierSmoothing);
// 使用高级贝塞尔曲线平滑
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAdvancedBezierSmoothing"), canvas.UseAdvancedBezierSmoothing);
2026-01-10 17:31:55 +08:00
// 启用异步墨迹平滑
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchUseAsyncInkSmoothing"), canvas.UseAsyncInkSmoothing);
2026-01-10 17:31:55 +08:00
// 启用硬件加速
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchUseHardwareAcceleration"), canvas.UseHardwareAcceleration);
2026-01-10 17:31:55 +08:00
// 启用直线自动拉直
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoStraightenLine"), canvas.AutoStraightenLine);
2026-01-10 17:31:55 +08:00
// 启用高精度直线拉直
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchHighPrecisionLineStraighten"), canvas.HighPrecisionLineStraighten);
2026-01-10 17:31:55 +08:00
// 启用直线端点吸附
2026-01-02 01:35:22 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchLineEndpointSnapping"), canvas.LineEndpointSnapping);
2026-01-10 17:31:55 +08:00
2026-01-10 17:32:14 +08:00
// 启用墨迹渐隐功能
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableInkFade"), canvas.EnableInkFade);
if (InkFadeTimePanel != null)
{
InkFadeTimePanel.Visibility = canvas.EnableInkFade ? Visibility.Visible : Visibility.Collapsed;
}
if (InkFadeTimeSlider != null)
{
InkFadeTimeSlider.Value = canvas.InkFadeTime;
}
2026-01-10 17:31:55 +08:00
// 定时自动保存墨迹
// 注意:这个设置可能在 Automation 或 Canvas 中,需要根据实际情况调整
// SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnableAutoSaveStrokes"), ...);
// 墨迹全页面保存
// SetToggleSwitchState(FindToggleSwitch("ToggleSwitchSaveFullPageStrokes"), ...);
// 保存为XML格式
// SetToggleSwitchState(FindToggleSwitch("ToggleSwitchSaveStrokesAsXML"), ...);
// 自动保存幻灯片墨迹
if (MainWindow.Settings.PowerPointSettings != null)
{
2026-03-03 16:04:20 +08:00
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchAutoSaveStrokesInPowerPoint"),
2026-01-10 17:31:55 +08:00
MainWindow.Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint);
}
2026-01-02 01:35:22 +08:00
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"加载画板和墨迹设置时出错: {ex.Message}");
}
_isLoaded = true;
}
2026-01-10 17:31:55 +08:00
/// <summary>
/// 查找ToggleSwitch控件
/// </summary>
2026-01-02 01:35:22 +08:00
private Border FindToggleSwitch(string name)
{
return this.FindDescendantByName(name) as Border;
}
2026-01-10 17:31:55 +08:00
/// <summary>
/// 设置ToggleSwitch状态
/// </summary>
2026-01-02 01:35:22 +08:00
private void SetToggleSwitchState(Border toggleSwitch, bool isOn)
{
if (toggleSwitch == null) return;
2026-03-03 16:04:20 +08:00
toggleSwitch.Background = isOn
? new SolidColorBrush(Color.FromRgb(53, 132, 228))
2026-02-06 22:06:50 +08:00
: (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225)));
2026-01-02 01:35:22 +08:00
var innerBorder = toggleSwitch.Child as Border;
if (innerBorder != null)
{
innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
2026-02-06 22:06:50 +08:00
innerBorder.Background = new SolidColorBrush(Colors.White);
2026-01-02 01:35:22 +08:00
}
}
2026-01-10 17:31:55 +08:00
/// <summary>
/// 设置选项按钮状态
/// </summary>
2026-01-02 01:35:22 +08:00
private void SetOptionButtonState(string group, int selectedIndex)
{
var buttons = new[] { "VerySmall", "Small", "Medium", "Large", "VeryLarge" };
var hyperbolaButtons = new[] { "Yes", "No", "Ask" };
2026-03-03 16:04:20 +08:00
2026-01-02 01:35:22 +08:00
string[] buttonNames = group == "EraserSize" ? buttons : hyperbolaButtons;
2026-03-03 16:04:20 +08:00
2026-02-07 14:02:26 +08:00
bool isDarkTheme = ThemeHelper.IsDarkTheme;
var selectedBrush = isDarkTheme ? new SolidColorBrush(Color.FromRgb(25, 25, 25)) : new SolidColorBrush(Color.FromRgb(225, 225, 225));
var unselectedBrush = new SolidColorBrush(Colors.Transparent);
2026-01-10 17:31:55 +08:00
for (int i = 0; i < buttonNames.Length && i <= selectedIndex; i++)
2026-01-02 01:35:22 +08:00
{
var button = this.FindDescendantByName($"{group}{buttonNames[i]}") as Border;
if (button != null)
{
2026-01-10 17:31:55 +08:00
if (i == selectedIndex)
{
2026-02-07 14:02:26 +08:00
button.Background = selectedBrush;
2026-01-10 17:31:55 +08:00
var textBlock = button.Child as TextBlock;
if (textBlock != null)
{
textBlock.FontWeight = FontWeights.Bold;
2026-02-07 14:02:26 +08:00
textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush();
2026-01-10 17:31:55 +08:00
}
}
else
{
2026-02-07 14:02:26 +08:00
button.Background = unselectedBrush;
2026-01-10 17:31:55 +08:00
var textBlock = button.Child as TextBlock;
if (textBlock != null)
{
textBlock.FontWeight = FontWeights.Normal;
2026-02-07 14:02:26 +08:00
textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush();
2026-01-10 17:31:55 +08:00
}
}
2026-01-02 01:35:22 +08:00
}
}
}
2026-02-07 10:37:51 +08:00
private bool GetCurrentSettingValue(string tag)
{
if (MainWindow.Settings?.Canvas == null) return false;
try
{
var canvas = MainWindow.Settings.Canvas;
switch (tag)
{
case "ShowCursor":
return canvas.IsShowCursor;
case "EnablePressureTouchMode":
return canvas.EnablePressureTouchMode;
case "DisablePressure":
return canvas.DisablePressure;
case "HideStrokeWhenSelecting":
return canvas.HideStrokeWhenSelecting;
case "ClearCanvasAndClearTimeMachine":
return canvas.ClearCanvasAndClearTimeMachine;
case "ClearCanvasAlsoClearImages":
return canvas.ClearCanvasAlsoClearImages;
case "CompressPicturesUploaded":
return canvas.IsCompressPicturesUploaded;
case "ShowCircleCenter":
return canvas.ShowCircleCenter;
case "FitToCurve":
return canvas.FitToCurve && !canvas.UseAdvancedBezierSmoothing;
case "AdvancedBezierSmoothing":
return canvas.UseAdvancedBezierSmoothing;
case "UseAsyncInkSmoothing":
return canvas.UseAsyncInkSmoothing;
case "UseHardwareAcceleration":
return canvas.UseHardwareAcceleration;
case "AutoStraightenLine":
return canvas.AutoStraightenLine;
case "HighPrecisionLineStraighten":
return canvas.HighPrecisionLineStraighten;
case "LineEndpointSnapping":
return canvas.LineEndpointSnapping;
case "EnableInkFade":
return canvas.EnableInkFade;
case "HideInkFadeControlInPenMenu":
return canvas.HideInkFadeControlInPenMenu;
case "EnableAutoSaveStrokes":
return MainWindow.Settings.Automation?.IsEnableAutoSaveStrokes ?? false;
case "SaveFullPageStrokes":
return MainWindow.Settings.Automation?.IsSaveFullPageStrokes ?? false;
case "SaveStrokesAsXML":
return MainWindow.Settings.Automation?.IsSaveStrokesAsXML ?? false;
case "AutoSaveStrokesInPowerPoint":
return MainWindow.Settings.PowerPointSettings?.IsAutoSaveStrokesInPowerPoint ?? false;
default:
return false;
}
}
catch
{
return false;
}
}
2026-01-10 17:31:55 +08:00
/// <summary>
/// ToggleSwitch点击事件处理
/// </summary>
2026-01-02 01:35:22 +08:00
private void ToggleSwitch_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;
2026-02-07 10:37:51 +08:00
bool currentState = GetCurrentSettingValue(tag);
bool newState = !currentState;
SetToggleSwitchState(border, newState);
2026-01-02 01:35:22 +08:00
var canvas = MainWindow.Settings.Canvas;
if (canvas == null) return;
switch (tag)
{
case "ShowCursor":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchShowCursor", newState);
break;
case "EnablePressureTouchMode":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnablePressureTouchMode", newState);
2026-01-10 17:31:55 +08:00
// 处理互斥逻辑
2026-01-02 01:35:22 +08:00
if (newState && canvas.DisablePressure)
{
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchDisablePressure", false);
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchDisablePressure"), false);
}
break;
case "DisablePressure":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchDisablePressure", newState);
2026-01-10 17:31:55 +08:00
// 处理互斥逻辑
2026-01-02 01:35:22 +08:00
if (newState && canvas.EnablePressureTouchMode)
{
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnablePressureTouchMode", false);
SetToggleSwitchState(FindToggleSwitch("ToggleSwitchEnablePressureTouchMode"), false);
}
break;
case "HideStrokeWhenSelecting":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchHideStrokeWhenSelecting", newState);
break;
case "ClearCanvasAndClearTimeMachine":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchClearCanvasAndClearTimeMachine", newState);
break;
case "ClearCanvasAlsoClearImages":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchClearCanvasAlsoClearImages", newState);
break;
case "CompressPicturesUploaded":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchCompressPicturesUploaded", newState);
break;
2026-01-10 17:32:14 +08:00
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;
2026-01-02 01:35:22 +08:00
case "UseAsyncInkSmoothing":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAsyncInkSmoothing", newState);
break;
case "UseHardwareAcceleration":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchHardwareAcceleration", newState);
break;
case "AutoStraightenLine":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoStraightenLine", newState);
break;
case "HighPrecisionLineStraighten":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchHighPrecisionLineStraighten", newState);
break;
case "LineEndpointSnapping":
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchLineEndpointSnapping", newState);
break;
2026-01-10 17:32:14 +08:00
case "EnableInkFade":
// 调用 MainWindow 中的方法
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableInkFade", newState);
// 更新UI状态
if (InkFadeTimePanel != null)
{
InkFadeTimePanel.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
}
break;
case "HideInkFadeControlInPenMenu":
// 调用 MainWindow 中的方法
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchHideInkFadeControlInPenMenu", newState);
break;
2026-01-10 17:31:55 +08:00
case "EnableAutoSaveStrokes":
// 调用 MainWindow 中的方法
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchEnableAutoSaveStrokes", newState);
2026-01-02 01:35:22 +08:00
break;
2026-01-10 17:31:55 +08:00
case "SaveFullPageStrokes":
// 调用 MainWindow 中的方法
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchSaveFullPageStrokes", newState);
2026-01-02 01:35:22 +08:00
break;
2026-01-10 17:31:55 +08:00
case "SaveStrokesAsXML":
// 调用 MainWindow 中的方法
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchSaveStrokesAsXML", newState);
2026-01-02 01:35:22 +08:00
break;
2026-01-10 17:31:55 +08:00
case "AutoSaveStrokesInPowerPoint":
// 调用 MainWindow 中的方法
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchAutoSaveStrokesInPowerPoint", newState);
2026-01-02 01:35:22 +08:00
break;
}
}
2026-01-10 17:31:55 +08:00
/// <summary>
/// 选项按钮点击事件处理
/// </summary>
2026-01-02 01:35:22 +08:00
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];
2026-02-07 14:02:26 +08:00
bool isDarkTheme = ThemeHelper.IsDarkTheme;
var selectedBrush = isDarkTheme ? new SolidColorBrush(Color.FromRgb(25, 25, 25)) : new SolidColorBrush(Color.FromRgb(225, 225, 225));
var unselectedBrush = new SolidColorBrush(Colors.Transparent);
2026-01-02 01:35:22 +08:00
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 + "_"))
{
2026-02-07 14:02:26 +08:00
childBorder.Background = unselectedBrush;
2026-01-10 17:31:55 +08:00
var textBlock = childBorder.Child as TextBlock;
if (textBlock != null)
{
textBlock.FontWeight = FontWeights.Normal;
2026-02-07 14:02:26 +08:00
textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush();
2026-01-10 17:31:55 +08:00
}
2026-01-02 01:35:22 +08:00
}
}
}
}
2026-02-07 14:02:26 +08:00
border.Background = selectedBrush;
2026-01-10 17:31:55 +08:00
var currentTextBlock = border.Child as TextBlock;
if (currentTextBlock != null)
{
currentTextBlock.FontWeight = FontWeights.Bold;
2026-02-07 14:02:26 +08:00
currentTextBlock.Foreground = ThemeHelper.GetTextPrimaryBrush();
2026-01-10 17:31:55 +08:00
}
2026-01-02 01:35:22 +08:00
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;
}
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
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
{
2026-01-10 17:31:55 +08:00
// 如果找不到控件,直接更新设置
2026-01-02 01:35:22 +08:00
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;
}
2026-01-10 17:31:55 +08:00
// 调用 MainWindow 中的方法
2026-01-02 01:35:22 +08:00
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
{
2026-01-10 17:31:55 +08:00
// 如果找不到控件,直接更新设置
2026-01-02 01:35:22 +08:00
MainWindowSettingsHelper.UpdateSettingDirectly(() =>
{
canvas.HyperbolaAsymptoteOption = option;
}, "ComboBoxHyperbolaAsymptoteOption");
}
}
break;
2026-01-10 17:31:55 +08:00
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;
2026-01-02 01:35:22 +08:00
}
}
2026-01-10 17:31:55 +08:00
/// <summary>
/// 自动保存间隔选项按钮点击事件处理
/// </summary>
private void AutoSaveIntervalButton_Click(object sender, RoutedEventArgs e)
2026-01-02 01:35:22 +08:00
{
if (!_isLoaded) return;
2026-01-10 17:31:55 +08:00
OptionButton_Click(sender, e);
2026-01-02 01:35:22 +08:00
}
2026-01-10 17:31:55 +08:00
/// <summary>
/// Slider值变化事件处理
/// </summary>
2026-01-10 17:32:14 +08:00
private void InkFadeTimeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!_isLoaded) return;
if (InkFadeTimeSlider != null && InkFadeTimeText != null)
{
double value = InkFadeTimeSlider.Value;
InkFadeTimeText.Text = $"{(int)value}ms";
// 调用 MainWindow 中的方法
MainWindowSettingsHelper.InvokeSliderValueChanged("InkFadeTimeSlider", value);
}
}
2026-03-03 16:04:20 +08:00
2026-01-10 17:31:55 +08:00
/// <summary>
/// 应用主题
/// </summary>
2026-01-02 01:35:22 +08:00
public void ApplyTheme()
{
try
{
ThemeHelper.ApplyThemeToControl(this);
2026-02-07 10:37:51 +08:00
if (_isLoaded)
{
LoadSettings();
}
2026-01-02 01:35:22 +08:00
}
catch (Exception ex)
{
2026-01-10 17:31:55 +08:00
System.Diagnostics.Debug.WriteLine($"CanvasAndInkPanel 应用主题时出错: {ex.Message}");
2026-01-02 01:35:22 +08:00
}
}
2025-12-28 08:48:09 +08:00
}
}