diff --git a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs index 40df9e3..956e065 100644 --- a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs +++ b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.Globalization; using System.Net.Mime; +using System.Windows.Input; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Metadata; @@ -464,6 +465,33 @@ public abstract class NumericUpDownBase : NumericUpDown where T : struct, ICo set => SetValue(EmptyInputValueProperty, value); } + + public static readonly StyledProperty CommandProperty = AvaloniaProperty.Register( + nameof(Command)); + + public ICommand? Command + { + get => GetValue(CommandProperty); + set => SetValue(CommandProperty, value); + } + + public static readonly StyledProperty CommandParameterProperty = + AvaloniaProperty.Register(nameof(CommandParameter)); + + public object? CommandParameter + { + get => this.GetValue(CommandParameterProperty); + set => this.SetValue(CommandParameterProperty, value); + } + + private void InvokeCommand(object? cp) + { + if (this.Command != null && this.Command.CanExecute(cp)) + { + this.Command.Execute(cp); + } + } + /// /// Defines the event. /// @@ -504,11 +532,17 @@ public abstract class NumericUpDownBase : NumericUpDown where T : struct, ICo if (IsInitialized) { SyncTextAndValue(false, null, true); + SetValidSpinDirection(); + T? oldValue = args.GetOldValue(); + T? newValue = args.GetNewValue(); + var e = new ValueChangedEventArgs(ValueChangedEvent, oldValue, newValue); + RaiseEventCommand(e); } - SetValidSpinDirection(); - T? oldValue = args.GetOldValue(); - T? newValue = args.GetNewValue(); - var e = new ValueChangedEventArgs(ValueChangedEvent, oldValue, newValue); + } + + private void RaiseEventCommand(ValueChangedEventArgs e) + { + InvokeCommand(this.CommandParameter ?? e.NewValue); RaiseEvent(e); }