From 1e8ddf47544f2ba1a13e9242f3b856eb0330f540 Mon Sep 17 00:00:00 2001 From: PrefacedCorg <1876568293@qq.com> Date: Tue, 14 Apr 2026 12:47:54 +0800 Subject: [PATCH] =?UTF-8?q?=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml | 133 +++------------------- InkCanvas.Controls/GeometryButton.xaml | 23 ++++ InkCanvas.Controls/GeometryButton.xaml.cs | 62 ++++++++++ 3 files changed, 98 insertions(+), 120 deletions(-) create mode 100644 InkCanvas.Controls/GeometryButton.xaml create mode 100644 InkCanvas.Controls/GeometryButton.xaml.cs diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 7583daf9..18aa4d3d 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -8089,96 +8089,15 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + @@ -8197,36 +8116,10 @@ - - - - - - - - - - - - + + + + diff --git a/InkCanvas.Controls/GeometryButton.xaml b/InkCanvas.Controls/GeometryButton.xaml new file mode 100644 index 00000000..d79c9cbe --- /dev/null +++ b/InkCanvas.Controls/GeometryButton.xaml @@ -0,0 +1,23 @@ + + + + + diff --git a/InkCanvas.Controls/GeometryButton.xaml.cs b/InkCanvas.Controls/GeometryButton.xaml.cs new file mode 100644 index 00000000..4ce60a3a --- /dev/null +++ b/InkCanvas.Controls/GeometryButton.xaml.cs @@ -0,0 +1,62 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; + +namespace Ink_Canvas.Controls +{ + public partial class GeometryButton : UserControl + { + public static readonly DependencyProperty LabelProperty = DependencyProperty.Register( + nameof(Label), typeof(string), typeof(GeometryButton), + new PropertyMetadata(string.Empty, OnLabelChanged)); + + private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var button = (GeometryButton)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 IconSourceProperty = DependencyProperty.Register( + nameof(IconSource), typeof(ImageSource), typeof(GeometryButton), + new PropertyMetadata(null, OnIconSourceChanged)); + + private static void OnIconSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var button = (GeometryButton)d; + if (button.ButtonImage != null) + button.ButtonImage.Source = (ImageSource)e.NewValue; + } + + public ImageSource IconSource + { + get => (ImageSource)GetValue(IconSourceProperty); + set => SetValue(IconSourceProperty, value); + } + + public event MouseButtonEventHandler ButtonMouseDown; + public event MouseButtonEventHandler ButtonMouseUp; + + public GeometryButton() + { + InitializeComponent(); + } + + private void ButtonPanel_MouseDown(object sender, MouseButtonEventArgs e) + { + ButtonMouseDown?.Invoke(this, e); + } + + private void ButtonPanel_MouseUp(object sender, MouseButtonEventArgs e) + { + ButtonMouseUp?.Invoke(this, e); + } + } +}