From 63585911a72f7947c768c8c6acb21c64fd95d3bf Mon Sep 17 00:00:00 2001
From: CJKmkp <2564608840@qq.com>
Date: Fri, 2 Jan 2026 14:17:40 +0800
Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../SettingsViews/AppearancePanel.xaml | 12 +--
.../SettingsViews/ComboBoxStyles.xaml | 6 ++
.../SettingsViews/CrashActionPanel.xaml | 4 +-
.../SettingsViews/CrashActionPanel.xaml.cs | 69 +++++++++++++-
.../SettingsViews/StartupPanel.xaml.cs | 4 +-
.../SettingsViews/ThemeHelper.cs | 90 +++++++++++++++----
.../SettingsViews/ThemePanel.xaml.cs | 28 ++----
.../SettingsViews/SettingsWindow.xaml.cs | 4 +-
8 files changed, 166 insertions(+), 51 deletions(-)
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/AppearancePanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/AppearancePanel.xaml
index 3bc677f5..be81ef4a 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/AppearancePanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/AppearancePanel.xaml
@@ -40,7 +40,7 @@
-
+
@@ -104,7 +104,7 @@
-
+
@@ -292,7 +292,7 @@
-
+
@@ -304,7 +304,7 @@
-
+
@@ -399,7 +399,7 @@
-
+
@@ -429,7 +429,7 @@
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ComboBoxStyles.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/ComboBoxStyles.xaml
index 8e56336d..89b7d02a 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/ComboBoxStyles.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ComboBoxStyles.xaml
@@ -116,15 +116,21 @@
+
+
+
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml
index 9eb13b1a..3dcb3f05 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml
@@ -22,10 +22,10 @@
TextWrapping="Wrap" Foreground="#9a9996" FontSize="11" Margin="0,3.5,0,0" HorizontalAlignment="Left" MaxWidth="450"/>
-
+
-
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml.cs
index e2897f1c..8a138375 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/CrashActionPanel.xaml.cs
@@ -1,6 +1,8 @@
using System;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Input;
+using Ink_Canvas;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -9,6 +11,13 @@ namespace Ink_Canvas.Windows.SettingsViews
public CrashActionPanel()
{
InitializeComponent();
+ Loaded += CrashActionPanel_Loaded;
+ }
+
+ private void CrashActionPanel_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ ApplyTheme();
}
public event EventHandler IsTopBarNeedShadowEffect;
@@ -26,17 +35,73 @@ namespace Ink_Canvas.Windows.SettingsViews
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
}
}
+
+ public void LoadSettings()
+ {
+ try
+ {
+ if (App.CrashAction == App.CrashActionType.SilentRestart)
+ {
+ ThemeHelper.SetOptionButtonSelectedState(CrashActionSilentRestartBorder, true);
+ ThemeHelper.SetOptionButtonSelectedState(CrashActionNoActionBorder, false);
+ }
+ else
+ {
+ ThemeHelper.SetOptionButtonSelectedState(CrashActionSilentRestartBorder, false);
+ ThemeHelper.SetOptionButtonSelectedState(CrashActionNoActionBorder, true);
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"CrashActionPanel 加载设置时出错: {ex.Message}");
+ }
+ }
+
+ private void OptionButton_Click(object sender, MouseButtonEventArgs e)
+ {
+ var border = sender as Border;
+ if (border != null)
+ {
+ string tag = border.Tag?.ToString();
+ if (!string.IsNullOrEmpty(tag))
+ {
+ // 清除同组其他按钮的选中状态
+ if (tag == "CrashAction_SilentRestart")
+ {
+ ThemeHelper.SetOptionButtonSelectedState(CrashActionSilentRestartBorder, true);
+ ThemeHelper.SetOptionButtonSelectedState(CrashActionNoActionBorder, false);
+ App.CrashAction = App.CrashActionType.SilentRestart;
+ if (MainWindow.Settings?.Startup != null)
+ {
+ MainWindow.Settings.Startup.CrashAction = (int)App.CrashActionType.SilentRestart;
+ }
+ }
+ else if (tag == "CrashAction_NoAction")
+ {
+ ThemeHelper.SetOptionButtonSelectedState(CrashActionSilentRestartBorder, false);
+ ThemeHelper.SetOptionButtonSelectedState(CrashActionNoActionBorder, true);
+ App.CrashAction = App.CrashActionType.NoAction;
+ if (MainWindow.Settings?.Startup != null)
+ {
+ MainWindow.Settings.Startup.CrashAction = (int)App.CrashActionType.NoAction;
+ }
+ }
+ }
+ }
+ }
+
public void ApplyTheme()
{
try
{
ThemeHelper.ApplyThemeToControl(this);
+ // 重新应用按钮状态以适配主题
+ LoadSettings();
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"CrashActionPanel 应用主题时出�? {ex.Message}");
+ System.Diagnostics.Debug.WriteLine($"CrashActionPanel 应用主题时出错: {ex.Message}");
}
}
}
}
-
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs
index 0403c705..0dfaa815 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs
@@ -218,7 +218,9 @@ namespace Ink_Canvas.Windows.SettingsViews
private void SetToggleSwitchState(Border toggleSwitch, bool isOn)
{
if (toggleSwitch == null) return;
- toggleSwitch.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) : new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ toggleSwitch.Background = isOn
+ ? ThemeHelper.GetToggleSwitchOnBackgroundBrush()
+ : ThemeHelper.GetToggleSwitchOffBackgroundBrush();
var innerBorder = toggleSwitch.Child as Border;
if (innerBorder != null)
{
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs
index c7db8819..649a4010 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemeHelper.cs
@@ -1,4 +1,5 @@
using System;
+using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@@ -49,9 +50,9 @@ namespace Ink_Canvas.Windows.SettingsViews
public static Color ToggleSwitchOnBackground => IsDarkTheme ? Color.FromRgb(0, 122, 204) : Color.FromRgb(53, 132, 228);
public static Color ToggleSwitchOffBackground => IsDarkTheme ? ButtonBackground : Color.FromRgb(225, 225, 225);
public static Color OptionButtonSelectedBackground => SelectedBackground;
- public static Color OptionButtonUnselectedBackground => Colors.Transparent;
+ public static Color OptionButtonUnselectedBackground => ButtonBackground;
public static Color OptionButtonSelectedBorder => IsDarkTheme ? Color.FromRgb(100, 100, 100) : Color.FromRgb(160, 160, 160);
- public static Color OptionButtonUnselectedBorder => IsDarkTheme ? Color.FromRgb(50, 50, 50) : Color.FromRgb(220, 220, 220);
+ public static Color OptionButtonUnselectedBorder => IsDarkTheme ? Color.FromRgb(90, 90, 90) : Color.FromRgb(220, 220, 220);
public static Color TextBoxBackground => IsDarkTheme ? Color.FromRgb(43, 43, 43) : Color.FromRgb(255, 255, 255);
public static Color TextBoxBorder => IsDarkTheme ? Color.FromRgb(62, 62, 62) : Color.FromRgb(200, 200, 200);
public static Color ScrollBarTrack => IsDarkTheme ? Color.FromRgb(25, 25, 25) : Color.FromRgb(243, 243, 243);
@@ -585,11 +586,12 @@ namespace Ink_Canvas.Windows.SettingsViews
var border = comboBoxItem.Template.FindName("Border", comboBoxItem) as System.Windows.Controls.Border;
if (border != null)
{
+ // 优先检查当前状态
if (comboBoxItem.IsSelected)
{
border.Background = GetSelectedBackgroundBrush();
- border.BorderBrush = GetBorderPrimaryBrush();
- border.BorderThickness = new Thickness(1);
+ border.BorderBrush = new SolidColorBrush(Colors.Transparent);
+ border.BorderThickness = new Thickness(0);
}
else if (comboBoxItem.IsMouseOver)
{
@@ -609,7 +611,8 @@ namespace Ink_Canvas.Windows.SettingsViews
}
else if (color.R == 245 && color.G == 245 && color.B == 245)
{
- border.Background = GetHoverBackgroundBrush();
+ // 如果当前是悬浮颜色,但 IsMouseOver 为 false,说明鼠标已离开,恢复默认
+ border.Background = GetTextBoxBackgroundBrush();
}
else if (color.R == 225 && color.G == 225 && color.B == 225)
{
@@ -645,25 +648,76 @@ namespace Ink_Canvas.Windows.SettingsViews
comboBoxItem.MouseLeave += ComboBoxItem_MouseLeave;
comboBoxItem.Selected += ComboBoxItem_Selected;
comboBoxItem.Unselected += ComboBoxItem_Unselected;
+
+ var descriptor = System.ComponentModel.DependencyPropertyDescriptor.FromProperty(
+ System.Windows.UIElement.IsMouseOverProperty, typeof(System.Windows.UIElement));
+ if (descriptor != null)
+ {
+ descriptor.RemoveValueChanged(comboBoxItem, ComboBoxItem_IsMouseOverChanged);
+ descriptor.AddValueChanged(comboBoxItem, ComboBoxItem_IsMouseOverChanged);
+ }
}
catch
{
}
}
+
+ private static void ComboBoxItem_IsMouseOverChanged(object sender, EventArgs e)
+ {
+ if (sender is System.Windows.Controls.ComboBoxItem comboBoxItem)
+ {
+ comboBoxItem.Dispatcher.BeginInvoke(new Action(() =>
+ {
+ var border = comboBoxItem.Template?.FindName("Border", comboBoxItem) as System.Windows.Controls.Border;
+ if (border != null)
+ {
+ if (comboBoxItem.IsSelected)
+ {
+ border.Background = GetSelectedBackgroundBrush();
+ border.BorderBrush = new SolidColorBrush(Colors.Transparent);
+ border.BorderThickness = new Thickness(0);
+ }
+ else if (comboBoxItem.IsMouseOver)
+ {
+ border.Background = GetHoverBackgroundBrush();
+ border.BorderBrush = new SolidColorBrush(Colors.Transparent);
+ border.BorderThickness = new Thickness(0);
+ }
+ else
+ {
+ border.Background = GetTextBoxBackgroundBrush();
+ border.BorderBrush = new SolidColorBrush(Colors.Transparent);
+ border.BorderThickness = new Thickness(0);
+ }
+ }
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+ }
private static void ComboBoxItem_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
if (sender is System.Windows.Controls.ComboBoxItem comboBoxItem)
{
- var border = comboBoxItem.Template?.FindName("Border", comboBoxItem) as System.Windows.Controls.Border;
- if (border != null)
+ // 使用 Dispatcher 确保在 XAML Trigger 之后执行
+ comboBoxItem.Dispatcher.BeginInvoke(new Action(() =>
{
- if (!comboBoxItem.IsSelected)
+ var border = comboBoxItem.Template?.FindName("Border", comboBoxItem) as System.Windows.Controls.Border;
+ if (border != null)
{
- border.Background = GetHoverBackgroundBrush();
- border.BorderBrush = new SolidColorBrush(Colors.Transparent);
- border.BorderThickness = new Thickness(0);
+ // 选中状态优先于悬浮状态
+ if (comboBoxItem.IsSelected)
+ {
+ border.Background = GetSelectedBackgroundBrush();
+ border.BorderBrush = new SolidColorBrush(Colors.Transparent);
+ border.BorderThickness = new Thickness(0);
+ }
+ else if (comboBoxItem.IsMouseOver)
+ {
+ border.Background = GetHoverBackgroundBrush();
+ border.BorderBrush = new SolidColorBrush(Colors.Transparent);
+ border.BorderThickness = new Thickness(0);
+ }
}
- }
+ }), System.Windows.Threading.DispatcherPriority.Loaded);
}
}
private static void ComboBoxItem_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
@@ -676,8 +730,8 @@ namespace Ink_Canvas.Windows.SettingsViews
if (comboBoxItem.IsSelected)
{
border.Background = GetSelectedBackgroundBrush();
- border.BorderBrush = GetBorderPrimaryBrush();
- border.BorderThickness = new Thickness(1);
+ border.BorderBrush = new SolidColorBrush(Colors.Transparent);
+ border.BorderThickness = new Thickness(0);
}
else
{
@@ -696,8 +750,8 @@ namespace Ink_Canvas.Windows.SettingsViews
if (border != null)
{
border.Background = GetSelectedBackgroundBrush();
- border.BorderBrush = GetBorderPrimaryBrush();
- border.BorderThickness = new Thickness(1);
+ border.BorderBrush = new SolidColorBrush(Colors.Transparent);
+ border.BorderThickness = new Thickness(0);
}
}
}
@@ -767,13 +821,13 @@ namespace Ink_Canvas.Windows.SettingsViews
baseTrigger.Property == System.Windows.Controls.ComboBoxItem.IsSelectedProperty &&
(bool)baseTrigger.Value == true)
{
- setterBase.Value = GetBorderPrimaryBrush();
+ setterBase.Value = new SolidColorBrush(Colors.Transparent);
}
else if (setterBase.Property == System.Windows.Controls.Border.BorderThicknessProperty &&
baseTrigger.Property == System.Windows.Controls.ComboBoxItem.IsSelectedProperty &&
(bool)baseTrigger.Value == true)
{
- setterBase.Value = new Thickness(1);
+ setterBase.Value = new Thickness(0);
}
}
}
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs
index 55b071f4..2494af0b 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/ThemePanel.xaml.cs
@@ -229,8 +229,8 @@ namespace Ink_Canvas.Windows.SettingsViews
{
if (toggleSwitch == null) return;
toggleSwitch.Background = isOn
- ? new SolidColorBrush(Color.FromRgb(53, 132, 228))
- : new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ ? ThemeHelper.GetToggleSwitchOnBackgroundBrush()
+ : ThemeHelper.GetToggleSwitchOffBackgroundBrush();
var innerBorder = toggleSwitch.Child as Border;
if (innerBorder != null)
{
@@ -476,23 +476,11 @@ namespace Ink_Canvas.Windows.SettingsViews
var button = this.FindDescendantByName($"{group}{buttonNames[i]}Border") as Border;
if (button != null)
{
- if (i == selectedIndex)
+ ThemeHelper.SetOptionButtonSelectedState(button, i == selectedIndex);
+ var textBlock = button.Child as TextBlock;
+ if (textBlock != null)
{
- 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;
- }
+ textBlock.FontWeight = i == selectedIndex ? FontWeights.Bold : FontWeights.Normal;
}
}
}
@@ -528,7 +516,7 @@ namespace Ink_Canvas.Windows.SettingsViews
string childTag = childBorder.Tag?.ToString();
if (!string.IsNullOrEmpty(childTag) && childTag.StartsWith(group + "_"))
{
- childBorder.Background = new SolidColorBrush(Colors.Transparent);
+ ThemeHelper.SetOptionButtonSelectedState(childBorder, false);
var textBlock = childBorder.Child as TextBlock;
if (textBlock != null)
{
@@ -540,7 +528,7 @@ namespace Ink_Canvas.Windows.SettingsViews
}
// 设置当前按钮为选中状态
- border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ ThemeHelper.SetOptionButtonSelectedState(border, true);
var currentTextBlock = border.Child as TextBlock;
if (currentTextBlock != null)
{
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs
index 4fad4269..5eb85f36 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs
@@ -1434,7 +1434,7 @@ namespace Ink_Canvas.Windows
ClearOtherOptionsInGroup(border, tag);
// 设置当前按钮为选中状态
- border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ ThemeHelper.SetOptionButtonSelectedState(border, true);
var textBlock = border.Child as TextBlock;
if (textBlock != null)
{
@@ -1464,7 +1464,7 @@ namespace Ink_Canvas.Windows
string childTag = border.Tag?.ToString();
if (!string.IsNullOrEmpty(childTag) && childTag.StartsWith(groupName + "_"))
{
- border.Background = new SolidColorBrush(Colors.Transparent);
+ ThemeHelper.SetOptionButtonSelectedState(border, false);
var textBlock = border.Child as TextBlock;
if (textBlock != null)
{