Merge pull request #186 from heartacker/acker/number_updown_command
number_updown_command
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
|
||||
<Grid ColumnDefinitions="*,*" RowDefinitions="100,*">
|
||||
<StackPanel Grid.ColumnSpan="2">
|
||||
<u:Divider Content="Change Right ->" />
|
||||
<u:Divider Content="Demo"/>
|
||||
<u:NumericUIntUpDown
|
||||
Name="numd"
|
||||
Width="{Binding Width}"
|
||||
@@ -30,6 +30,7 @@
|
||||
HorizontalContentAlignment="{Binding HorizontalContentAlignment}"
|
||||
AllowDrag="{Binding AllowDrag}"
|
||||
AllowSpin="{Binding AllowSpin}"
|
||||
Command="{Binding TrythisCommand}"
|
||||
FontFamily="{Binding FontFamily, Mode=OneWay}"
|
||||
FormatString="{Binding FormatString}"
|
||||
InnerLeftContent="{Binding InnerLeftContent}"
|
||||
@@ -42,6 +43,11 @@
|
||||
Step="{Binding Step}"
|
||||
Watermark="{Binding Watermark}"
|
||||
Value="{Binding Value}" />
|
||||
<TextBox
|
||||
Width="NaN"
|
||||
HorizontalAlignment="Center"
|
||||
IsReadOnly="true"
|
||||
Text="{Binding CommandUpdateText}" />
|
||||
<u:Divider Content="Demo" />
|
||||
</StackPanel>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Ursa.Controls;
|
||||
@@ -39,6 +40,17 @@ public partial class NumericUpDownDemoViewModel : ObservableObject
|
||||
|
||||
[ObservableProperty] private bool _IsEnable = true;
|
||||
|
||||
[ObservableProperty] private string _CommandUpdateText = "Command not Execute";
|
||||
|
||||
uint v = 0;
|
||||
[RelayCommand]
|
||||
// void Trythis()
|
||||
void Trythis(uint v)
|
||||
// void Trythis(object v)
|
||||
{
|
||||
CommandUpdateText = $"Command Exe,CommandParameter={v}";
|
||||
}
|
||||
|
||||
|
||||
public NumericUpDownDemoViewModel()
|
||||
{
|
||||
@@ -65,7 +77,7 @@ public partial class NumericUpDownDemoViewModel : ObservableObject
|
||||
|
||||
partial void OnValueChanging(uint oldValue, uint newValue)
|
||||
{
|
||||
Console.WriteLine(oldValue);
|
||||
// Console.WriteLine(oldValue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<T> : NumericUpDown where T : struct, ICo
|
||||
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>
|
||||
/// Defines the <see cref="ValueChanged"/> event.
|
||||
/// </summary>
|
||||
@@ -504,11 +532,17 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
|
||||
if (IsInitialized)
|
||||
{
|
||||
SyncTextAndValue(false, null, true);
|
||||
SetValidSpinDirection();
|
||||
T? oldValue = args.GetOldValue<T?>();
|
||||
T? newValue = args.GetNewValue<T?>();
|
||||
var e = new ValueChangedEventArgs<T>(ValueChangedEvent, oldValue, newValue);
|
||||
RaiseEventCommand(e);
|
||||
}
|
||||
SetValidSpinDirection();
|
||||
T? oldValue = args.GetOldValue<T?>();
|
||||
T? newValue = args.GetNewValue<T?>();
|
||||
var e = new ValueChangedEventArgs<T>(ValueChangedEvent, oldValue, newValue);
|
||||
}
|
||||
|
||||
private void RaiseEventCommand(ValueChangedEventArgs<T> e)
|
||||
{
|
||||
InvokeCommand(this.CommandParameter ?? e.NewValue);
|
||||
RaiseEvent(e);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user