From 2b012bc04284c2dbd5d6522cb3d4435f08986f1d Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sun, 21 Sep 2025 00:25:09 +0800 Subject: [PATCH] =?UTF-8?q?add:=E4=B8=BB=E9=A2=98=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/App.xaml | 1 - Ink Canvas/MainWindow.xaml | 302 +++++++++--------- Ink Canvas/MainWindow.xaml.cs | 144 ++++++++- Ink Canvas/MainWindow_cs/MW_AutoTheme.cs | 83 +++-- .../MainWindow_cs/MW_FloatingBarIcons.cs | 10 +- Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs | 3 + Ink Canvas/Resources/Styles/Dark.xaml | 26 +- Ink Canvas/Resources/Styles/Light.xaml | 28 +- 8 files changed, 408 insertions(+), 189 deletions(-) diff --git a/Ink Canvas/App.xaml b/Ink Canvas/App.xaml index 0eecad8a..83167e38 100644 --- a/Ink Canvas/App.xaml +++ b/Ink Canvas/App.xaml @@ -237,7 +237,6 @@ - diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 6c377a93..73e81646 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -22,7 +22,7 @@ Height="9000" Width="1440" FontFamily="Microsoft YaHei UI" MouseWheel="Window_MouseWheel" - Foreground="Black" + Foreground="{DynamicResource FloatBarForeground}" SizeChanged="MainWindow_OnSizeChanged" MouseMove="MainWindow_OnMouseMove" Stylus.IsPressAndHoldEnabled="False" @@ -186,6 +186,21 @@ + + + - - + + - + - + - - @@ -1028,6 +1029,19 @@ FontSize="26" /> + + + + + + + + + @@ -4092,7 +4106,7 @@ - @@ -4100,7 +4114,7 @@ - @@ -4114,7 +4128,7 @@ Text="{Binding ElementName=TextBlockWhiteBoardIndexInfo, Path=Text}" Margin="0,-1,0,0" FontSize="17" FontWeight="Bold" TextAlignment="Center" /> - @@ -4122,7 +4136,7 @@ - @@ -4190,7 +4204,7 @@ - @@ -4208,14 +4222,14 @@ - - @@ -4245,17 +4259,17 @@ - @@ -4264,7 +4278,7 @@ - - @@ -4450,14 +4464,14 @@ - @@ -4473,14 +4487,14 @@ - @@ -4498,7 +4512,7 @@ @@ -4525,7 +4539,7 @@ Canvas.Left="9" Canvas.Right="9" Canvas.Bottom="0"> - @@ -5379,14 +5393,14 @@ - @@ -5403,7 +5417,7 @@ @@ -5599,7 +5613,7 @@ - @@ -5613,18 +5627,18 @@ - - - - @@ -5786,14 +5800,14 @@ - - @@ -5808,7 +5822,7 @@ - + @@ -5890,14 +5904,14 @@ - - + @@ -5907,14 +5921,14 @@ - - @@ -5934,14 +5948,14 @@ - - @@ -5957,7 +5971,7 @@ @@ -5993,7 +6007,7 @@ - @@ -6013,7 +6027,7 @@ - @@ -6033,7 +6047,7 @@ - @@ -6056,7 +6070,7 @@ - @@ -6076,7 +6090,7 @@ - @@ -6096,7 +6110,7 @@ - @@ -6119,7 +6133,7 @@ - @@ -6139,7 +6153,7 @@ - @@ -6159,7 +6173,7 @@ - @@ -6187,14 +6201,14 @@ - - @@ -6221,14 +6235,14 @@ - - @@ -6247,7 +6261,7 @@ - @@ -6255,7 +6269,7 @@ - @@ -6269,7 +6283,7 @@ Text="{Binding ElementName=TextBlockWhiteBoardIndexInfo, Path=Text}" Margin="0,-1,0,0" FontSize="17" FontWeight="Bold" TextAlignment="Center" /> - @@ -6277,7 +6291,7 @@ - @@ -6345,7 +6359,7 @@ - @@ -6448,10 +6462,10 @@ - + FontSize="16" Foreground="{DynamicResource SettingsPageForeground}" /> @@ -6869,7 +6883,7 @@ @@ -6877,9 +6891,9 @@ @@ -6911,7 +6925,7 @@ - @@ -6927,14 +6941,14 @@ - - @@ -7537,7 +7551,7 @@ - @@ -7562,7 +7576,7 @@ Canvas.Left="9" Canvas.Right="9" Canvas.Bottom="0"> + Background="{DynamicResource FloatBarBackground}" CornerRadius="1" /> @@ -7595,7 +7609,7 @@ Orientation="Horizontal" Canvas.Left="14" Canvas.Right="14" Canvas.Bottom="0"> + Background="{DynamicResource FloatBarBackground}" CornerRadius="1" /> @@ -7774,7 +7788,7 @@ Height="23" Margin="0,0,0,0" /> @@ -8341,7 +8355,7 @@ - - - - - @@ -8676,7 +8690,7 @@ - @@ -8685,7 +8699,7 @@ - @@ -8713,7 +8727,7 @@ - - @@ -8745,7 +8759,7 @@ - - - - @@ -8940,20 +8954,20 @@ - - - @@ -9006,7 +9020,7 @@ - @@ -9026,7 +9040,7 @@ - @@ -9049,7 +9063,7 @@ - @@ -9069,7 +9083,7 @@ - @@ -9089,7 +9103,7 @@ - @@ -9112,7 +9126,7 @@ - @@ -9132,7 +9146,7 @@ - @@ -9152,7 +9166,7 @@ - @@ -9175,7 +9189,7 @@ - @@ -9192,7 +9206,7 @@ - @@ -9337,7 +9351,7 @@ EditingMode="None" Background="Transparent" /> @@ -9481,7 +9495,7 @@ + Foreground="{DynamicResource FloatBarForeground}" Text="1.0x" VerticalAlignment="Center"> @@ -9503,7 +9517,7 @@ - - + - + - + - + - + - + - - + - + - + - + - + - + + /// 主题下拉框选择变化事件 + /// + private void ComboBoxTheme_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (!isLoaded) return; + + try + { + System.Windows.Controls.ComboBox comboBox = sender as System.Windows.Controls.ComboBox; + if (comboBox != null) + { + Settings.Appearance.Theme = comboBox.SelectedIndex; + + // 应用新主题 + ApplyTheme(comboBox.SelectedIndex); + + // 保存设置 + SaveSettingsToFile(); + + // 显示通知 + string themeName; + switch (comboBox.SelectedIndex) + { + case 0: + themeName = "浅色主题"; + break; + case 1: + themeName = "深色主题"; + break; + case 2: + themeName = "跟随系统"; + break; + default: + themeName = "未知主题"; + break; + } + + ShowNotification($"已切换到{themeName}"); + } + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"切换主题时出错: {ex.Message}", LogHelper.LogType.Error); + ShowNotification("主题切换失败"); + } + } + + /// + /// 应用指定主题 + /// + /// 主题索引:0-浅色,1-深色,2-跟随系统 + private void ApplyTheme(int themeIndex) + { + try + { + switch (themeIndex) + { + case 0: // 浅色主题 + SetTheme("Light"); + // 浅色主题下设置浮动栏为完全不透明 + ViewboxFloatingBar.Opacity = 1.0; + break; + case 1: // 深色主题 + SetTheme("Dark"); + // 深色主题下设置浮动栏为完全不透明 + ViewboxFloatingBar.Opacity = 1.0; + break; + case 2: // 跟随系统 + if (IsSystemThemeLight()) + { + SetTheme("Light"); + ViewboxFloatingBar.Opacity = 1.0; + } + else + { + SetTheme("Dark"); + ViewboxFloatingBar.Opacity = 1.0; + } + break; + } + + // 强制刷新通知框的颜色资源 + RefreshNotificationColors(); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"应用主题时出错: {ex.Message}", LogHelper.LogType.Error); + } + } + + /// + /// 刷新通知框的颜色资源 + /// + private void RefreshNotificationColors() + { + try + { + // 强制刷新通知框的背景和前景色 + var border = GridNotifications.Children.OfType().FirstOrDefault(); + if (border != null) + { + border.Background = (Brush)Application.Current.FindResource("SettingsPageBackground"); + border.BorderBrush = new SolidColorBrush(Color.FromRgb(185, 28, 28)); // 保持红色边框 + } + + TextBlockNotice.Foreground = (Brush)Application.Current.FindResource("SettingsPageForeground"); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"刷新通知框颜色时出错: {ex.Message}", LogHelper.LogType.Error); + } + } + + #endregion } } diff --git a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs index f908c2ad..132c7056 100644 --- a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs +++ b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs @@ -1,61 +1,92 @@ using iNKORE.UI.WPF.Modern; using Microsoft.Win32; using System; +using System.Collections.Generic; using System.Windows; using System.Windows.Media; +using Ink_Canvas.Helpers; using Application = System.Windows.Application; namespace Ink_Canvas { public partial class MainWindow : Window { - private Color FloatBarForegroundColor = Color.FromRgb(102, 102, 102); + private Color FloatBarForegroundColor; private void SetTheme(string theme) { + // 清理现有的主题资源 + var resourcesToRemove = new List(); + foreach (var dict in Application.Current.Resources.MergedDictionaries) + { + if (dict.Source != null && + (dict.Source.ToString().Contains("Light.xaml") || + dict.Source.ToString().Contains("Dark.xaml"))) + { + resourcesToRemove.Add(dict); + } + } + + foreach (var dict in resourcesToRemove) + { + Application.Current.Resources.MergedDictionaries.Remove(dict); + } + + // 先添加其他资源 + var rd2 = new ResourceDictionary + { Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative) }; + Application.Current.Resources.MergedDictionaries.Add(rd2); + + var rd3 = new ResourceDictionary + { Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative) }; + Application.Current.Resources.MergedDictionaries.Add(rd3); + + var rd4 = new ResourceDictionary + { Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative) }; + Application.Current.Resources.MergedDictionaries.Add(rd4); + if (theme == "Light") { var rd1 = new ResourceDictionary { Source = new Uri("Resources/Styles/Light.xaml", UriKind.Relative) }; Application.Current.Resources.MergedDictionaries.Add(rd1); - var rd2 = new ResourceDictionary - { Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative) }; - Application.Current.Resources.MergedDictionaries.Add(rd2); - - var rd3 = new ResourceDictionary - { Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative) }; - Application.Current.Resources.MergedDictionaries.Add(rd3); - - var rd4 = new ResourceDictionary - { Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative) }; - Application.Current.Resources.MergedDictionaries.Add(rd4); - ThemeManager.SetRequestedTheme(window, ElementTheme.Light); - FloatBarForegroundColor = (Color)Application.Current.FindResource("FloatBarForegroundColor"); + InitializeFloatBarForegroundColor(); + + // 强制刷新UI + window.InvalidateVisual(); } else if (theme == "Dark") { var rd1 = new ResourceDictionary { Source = new Uri("Resources/Styles/Dark.xaml", UriKind.Relative) }; Application.Current.Resources.MergedDictionaries.Add(rd1); - var rd2 = new ResourceDictionary - { Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative) }; - Application.Current.Resources.MergedDictionaries.Add(rd2); - - var rd3 = new ResourceDictionary - { Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative) }; - Application.Current.Resources.MergedDictionaries.Add(rd3); - - var rd4 = new ResourceDictionary - { Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative) }; - Application.Current.Resources.MergedDictionaries.Add(rd4); - ThemeManager.SetRequestedTheme(window, ElementTheme.Dark); + InitializeFloatBarForegroundColor(); + + // 强制刷新UI + window.InvalidateVisual(); + } + } + + /// + /// 初始化FloatBarForegroundColor,从当前主题资源中加载颜色 + /// + private void InitializeFloatBarForegroundColor() + { + try + { FloatBarForegroundColor = (Color)Application.Current.FindResource("FloatBarForegroundColor"); } + catch (Exception ex) + { + // 如果无法从资源中加载,使用默认颜色 + FloatBarForegroundColor = Color.FromRgb(0, 0, 0); + LogHelper.WriteLogToFile($"初始化FloatBarForegroundColor时出错: {ex.Message}", LogHelper.LogType.Error); + } } private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e) diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs index a6df1ddd..31bb8798 100644 --- a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs +++ b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs @@ -404,17 +404,17 @@ namespace Ink_Canvas { if (mode != "clear") { - CursorIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27)); + CursorIconGeometry.Brush = new SolidColorBrush(FloatBarForegroundColor); CursorIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedCursorIcon); - PenIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27)); + PenIconGeometry.Brush = new SolidColorBrush(FloatBarForegroundColor); PenIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedPenIcon); - StrokeEraserIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27)); + StrokeEraserIconGeometry.Brush = new SolidColorBrush(FloatBarForegroundColor); StrokeEraserIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedEraserStrokeIcon); - CircleEraserIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27)); + CircleEraserIconGeometry.Brush = new SolidColorBrush(FloatBarForegroundColor); CircleEraserIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedEraserCircleIcon); - LassoSelectIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27)); + LassoSelectIconGeometry.Brush = new SolidColorBrush(FloatBarForegroundColor); LassoSelectIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedLassoSelectIcon); BoardPen.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); diff --git a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs index b2e29494..41b6a0fe 100644 --- a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs +++ b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs @@ -245,6 +245,9 @@ namespace Ink_Canvas break; } + // 设置主题下拉框 + ComboBoxTheme.SelectedIndex = Settings.Appearance.Theme; + ComboBoxChickenSoupSource.SelectedIndex = Settings.Appearance.ChickenSoupSource; ToggleSwitchEnableQuickPanel.IsOn = Settings.Appearance.IsShowQuickPanel; diff --git a/Ink Canvas/Resources/Styles/Dark.xaml b/Ink Canvas/Resources/Styles/Dark.xaml index 2dd756fc..1a7cfee4 100644 --- a/Ink Canvas/Resources/Styles/Dark.xaml +++ b/Ink Canvas/Resources/Styles/Dark.xaml @@ -1,7 +1,23 @@ - - - - + + + + + + #FFcccccc + + + + + + + + + + + + + Transparent + #2200CDCD + #4400CDCD \ No newline at end of file diff --git a/Ink Canvas/Resources/Styles/Light.xaml b/Ink Canvas/Resources/Styles/Light.xaml index 900ceccf..5413bc30 100644 --- a/Ink Canvas/Resources/Styles/Light.xaml +++ b/Ink Canvas/Resources/Styles/Light.xaml @@ -1,7 +1,23 @@ - - - - - #18181b + + + + + + + #FF000000 + + + + + + + + + + + + + Transparent + #66FFFFFF + #99FFFFFF \ No newline at end of file