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,*">
|
<Grid ColumnDefinitions="*,*" RowDefinitions="100,*">
|
||||||
<StackPanel Grid.ColumnSpan="2">
|
<StackPanel Grid.ColumnSpan="2">
|
||||||
<u:Divider Content="Change Right ->" />
|
<u:Divider Content="Demo"/>
|
||||||
<u:NumericUIntUpDown
|
<u:NumericUIntUpDown
|
||||||
Name="numd"
|
Name="numd"
|
||||||
Width="{Binding Width}"
|
Width="{Binding Width}"
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
HorizontalContentAlignment="{Binding HorizontalContentAlignment}"
|
HorizontalContentAlignment="{Binding HorizontalContentAlignment}"
|
||||||
AllowDrag="{Binding AllowDrag}"
|
AllowDrag="{Binding AllowDrag}"
|
||||||
AllowSpin="{Binding AllowSpin}"
|
AllowSpin="{Binding AllowSpin}"
|
||||||
|
Command="{Binding TrythisCommand}"
|
||||||
FontFamily="{Binding FontFamily, Mode=OneWay}"
|
FontFamily="{Binding FontFamily, Mode=OneWay}"
|
||||||
FormatString="{Binding FormatString}"
|
FormatString="{Binding FormatString}"
|
||||||
InnerLeftContent="{Binding InnerLeftContent}"
|
InnerLeftContent="{Binding InnerLeftContent}"
|
||||||
@@ -42,6 +43,11 @@
|
|||||||
Step="{Binding Step}"
|
Step="{Binding Step}"
|
||||||
Watermark="{Binding Watermark}"
|
Watermark="{Binding Watermark}"
|
||||||
Value="{Binding Value}" />
|
Value="{Binding Value}" />
|
||||||
|
<TextBox
|
||||||
|
Width="NaN"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
IsReadOnly="true"
|
||||||
|
Text="{Binding CommandUpdateText}" />
|
||||||
<u:Divider Content="Demo" />
|
<u:Divider Content="Demo" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Layout;
|
using Avalonia.Layout;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Ursa.Controls;
|
using Ursa.Controls;
|
||||||
@@ -39,6 +40,17 @@ public partial class NumericUpDownDemoViewModel : ObservableObject
|
|||||||
|
|
||||||
[ObservableProperty] private bool _IsEnable = true;
|
[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()
|
public NumericUpDownDemoViewModel()
|
||||||
{
|
{
|
||||||
@@ -65,7 +77,7 @@ public partial class NumericUpDownDemoViewModel : ObservableObject
|
|||||||
|
|
||||||
partial void OnValueChanging(uint oldValue, uint newValue)
|
partial void OnValueChanging(uint oldValue, uint newValue)
|
||||||
{
|
{
|
||||||
Console.WriteLine(oldValue);
|
// Console.WriteLine(oldValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
|
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?>();
|
private void RaiseEventCommand(ValueChangedEventArgs<T> e)
|
||||||
var e = new ValueChangedEventArgs<T>(ValueChangedEvent, oldValue, newValue);
|
{
|
||||||
|
InvokeCommand(this.CommandParameter ?? e.NewValue);
|
||||||
RaiseEvent(e);
|
RaiseEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user