Command
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
|
using System.Windows.Input;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Metadata;
|
using Avalonia.Controls.Metadata;
|
||||||
@@ -464,6 +465,33 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
|
|||||||
set => SetValue(EmptyInputValueProperty, value);
|
set => SetValue(EmptyInputValueProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static readonly StyledProperty<ICommand?> CommandProperty = AvaloniaProperty.Register<Pagination, ICommand?>(
|
||||||
|
nameof(Command));
|
||||||
|
|
||||||
|
public ICommand? Command
|
||||||
|
{
|
||||||
|
get => GetValue(CommandProperty);
|
||||||
|
set => SetValue(CommandProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<object?> CommandParameterProperty =
|
||||||
|
AvaloniaProperty.Register<Pagination, object?>(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the <see cref="ValueChanged"/> event.
|
/// Defines the <see cref="ValueChanged"/> event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -504,11 +532,17 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
|
|||||||
if (IsInitialized)
|
if (IsInitialized)
|
||||||
{
|
{
|
||||||
SyncTextAndValue(false, null, true);
|
SyncTextAndValue(false, null, true);
|
||||||
}
|
|
||||||
SetValidSpinDirection();
|
SetValidSpinDirection();
|
||||||
T? oldValue = args.GetOldValue<T?>();
|
T? oldValue = args.GetOldValue<T?>();
|
||||||
T? newValue = args.GetNewValue<T?>();
|
T? newValue = args.GetNewValue<T?>();
|
||||||
var e = new ValueChangedEventArgs<T>(ValueChangedEvent, oldValue, newValue);
|
var e = new ValueChangedEventArgs<T>(ValueChangedEvent, oldValue, newValue);
|
||||||
|
RaiseEventCommand(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RaiseEventCommand(ValueChangedEventArgs<T> e)
|
||||||
|
{
|
||||||
|
InvokeCommand(this.CommandParameter ?? e.NewValue);
|
||||||
RaiseEvent(e);
|
RaiseEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user