From 3eba662772b7c57c12fb9379aa720ecca07d2282 Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sun, 5 Oct 2025 09:14:29 +0800 Subject: [PATCH] =?UTF-8?q?improve:=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/InkCanvasForClass.csproj | 2 +- Ink Canvas/MainWindow.xaml | 10 ++-- Ink Canvas/MainWindow_cs/MW_AutoTheme.cs | 75 ++++++++++++++++++++++++ Ink Canvas/Resources/Styles/Dark.xaml | 7 +++ Ink Canvas/Resources/Styles/Light.xaml | 7 +++ 5 files changed, 95 insertions(+), 6 deletions(-) diff --git a/Ink Canvas/InkCanvasForClass.csproj b/Ink Canvas/InkCanvasForClass.csproj index 45a51123..2de08462 100644 --- a/Ink Canvas/InkCanvasForClass.csproj +++ b/Ink Canvas/InkCanvasForClass.csproj @@ -329,6 +329,7 @@ + @@ -621,7 +622,6 @@ - diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 9304e290..07ac4d68 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -3986,7 +3986,7 @@ CornerRadius="{Binding ElementName=BorderImageSelectionControl, Path=CornerRadius}" Width="40" MouseDown="Border_MouseDown" MouseUp="BorderImageClone_MouseUp"> - @@ -4002,7 +4002,7 @@ Visibility="{Binding Visibility, ElementName=GridBackgroundCover}"> - @@ -4045,14 +4045,14 @@ - - - + /// 刷新图片选中栏图标 + /// + private void RefreshImageSelectionIcons() + { + try + { + if (BorderImageSelectionControl != null) + { + // 强制刷新图片选中栏的视觉状态 + BorderImageSelectionControl.InvalidateVisual(); + + // 刷新图片选中栏内的所有图标 + var viewbox = BorderImageSelectionControl.Child as Viewbox; + if (viewbox?.Child is ui.SimpleStackPanel stackPanel) + { + RefreshImageSelectionIconsRecursive(stackPanel); + } + } + } + catch (Exception) + { + // 忽略异常,确保主题切换不会因为图标刷新失败而中断 + } + } + + /// + /// 递归刷新图片选中栏内的图标 + /// + private void RefreshImageSelectionIconsRecursive(System.Windows.Controls.Panel panel) + { + try + { + foreach (var child in panel.Children) + { + if (child is Image image) + { + // 强制刷新图像 + image.InvalidateVisual(); + } + else if (child is System.Windows.Controls.Panel childPanel) + { + // 递归处理子面板 + RefreshImageSelectionIconsRecursive(childPanel); + } + else if (child is Border border && border.Child is System.Windows.Controls.Panel borderPanel) + { + // 处理Border内的面板 + RefreshImageSelectionIconsRecursive(borderPanel); + } + else if (child is Grid grid) + { + // 处理Grid内的子元素 + foreach (var gridChild in grid.Children) + { + if (gridChild is Image gridImage) + { + gridImage.InvalidateVisual(); + } + } + } + } + } + catch (Exception) + { + // 忽略异常 + } + } } } \ No newline at end of file diff --git a/Ink Canvas/Resources/Styles/Dark.xaml b/Ink Canvas/Resources/Styles/Dark.xaml index a6be59a2..25f52bfd 100644 --- a/Ink Canvas/Resources/Styles/Dark.xaml +++ b/Ink Canvas/Resources/Styles/Dark.xaml @@ -57,6 +57,13 @@ + + + + + + + diff --git a/Ink Canvas/Resources/Styles/Light.xaml b/Ink Canvas/Resources/Styles/Light.xaml index f9d66cfb..6c7eb63b 100644 --- a/Ink Canvas/Resources/Styles/Light.xaml +++ b/Ink Canvas/Resources/Styles/Light.xaml @@ -57,6 +57,13 @@ + + + + + + +