63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
|
|
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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|