From b64b0a36181446649e28f35033277554fd3ff243 Mon Sep 17 00:00:00 2001 From: PrefacedCorg <1876568293@qq.com> Date: Mon, 13 Apr 2026 23:53:59 +0800 Subject: [PATCH] =?UTF-8?q?=20add:=E6=96=B0=E6=8E=A7=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml | 36 ++++----- InkCanvas.Controls/ToolMenuButton.xaml | 38 +++++++++ InkCanvas.Controls/ToolMenuButton.xaml.cs | 95 +++++++++++++++++++++++ 3 files changed, 151 insertions(+), 18 deletions(-) create mode 100644 InkCanvas.Controls/ToolMenuButton.xaml create mode 100644 InkCanvas.Controls/ToolMenuButton.xaml.cs diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 5863c3ba..31407aa9 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -6430,21 +6430,21 @@ - - - + + + - - - + + + - - - + + + @@ -8477,21 +8477,21 @@ - - - + + + - - - + + + - - - + + + diff --git a/InkCanvas.Controls/ToolMenuButton.xaml b/InkCanvas.Controls/ToolMenuButton.xaml new file mode 100644 index 00000000..d789f494 --- /dev/null +++ b/InkCanvas.Controls/ToolMenuButton.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + diff --git a/InkCanvas.Controls/ToolMenuButton.xaml.cs b/InkCanvas.Controls/ToolMenuButton.xaml.cs new file mode 100644 index 00000000..deb95d53 --- /dev/null +++ b/InkCanvas.Controls/ToolMenuButton.xaml.cs @@ -0,0 +1,95 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; + +namespace Ink_Canvas.Controls +{ + public partial class ToolMenuButton : UserControl + { + public static readonly DependencyProperty LabelProperty = DependencyProperty.Register( + nameof(Label), typeof(string), typeof(ToolMenuButton), + new PropertyMetadata(string.Empty, OnLabelChanged)); + + private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var button = (ToolMenuButton)d; + if (button.LabelControl != null) + button.LabelControl.Content = (string)e.NewValue; + } + + public string Label + { + get => (string)GetValue(LabelProperty); + set => SetValue(LabelProperty, value); + } + + public static readonly DependencyProperty IconGeometryProperty = DependencyProperty.Register( + nameof(IconGeometry), typeof(string), typeof(ToolMenuButton), + new PropertyMetadata(string.Empty, OnIconGeometryChanged)); + + private static void OnIconGeometryChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var button = (ToolMenuButton)d; + if (e.NewValue is string geometry && !string.IsNullOrEmpty(geometry) && button.IconGeometryInternal != null) + { + button.IconGeometryInternal.Geometry = Geometry.Parse(geometry); + } + } + + public string IconGeometry + { + get => (string)GetValue(IconGeometryProperty); + set => SetValue(IconGeometryProperty, value); + } + + public static readonly DependencyProperty IconBrushProperty = DependencyProperty.Register( + nameof(IconBrush), typeof(Brush), typeof(ToolMenuButton), + new PropertyMetadata(null, OnIconBrushChanged)); + + private static void OnIconBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var button = (ToolMenuButton)d; + if (button.IconGeometryInternal != null) + button.IconGeometryInternal.Brush = (Brush)e.NewValue; + } + + public Brush IconBrush + { + get => (Brush)GetValue(IconBrushProperty); + set => SetValue(IconBrushProperty, value); + } + + public new Brush Background + { + get => ButtonPanel.Background; + set => ButtonPanel.Background = value; + } + + public GeometryDrawing Icon => IconGeometryInternal; + + public event MouseButtonEventHandler ButtonMouseDown; + public event MouseEventHandler ButtonMouseLeave; + public event RoutedEventHandler ButtonMouseUp; + + public ToolMenuButton() + { + InitializeComponent(); + } + + private void ButtonPanel_MouseDown(object sender, MouseButtonEventArgs e) + { + ButtonMouseDown?.Invoke(this, e); + } + + private void ButtonPanel_MouseLeave(object sender, MouseEventArgs e) + { + ButtonMouseLeave?.Invoke(this, e); + } + + private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e) + { + ButtonMouseUp?.Invoke(this, new RoutedEventArgs(e.RoutedEvent, this)); + } + } +}