Merge pull request #314 from irihitech/numeirc-validation

Fix: fix numeric updown validation error display issue
This commit is contained in:
Dong Bin
2024-07-27 15:21:42 +08:00
committed by GitHub
3 changed files with 19 additions and 1 deletions

View File

@@ -380,7 +380,7 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
}
public static readonly StyledProperty<T?> ValueProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T?>(
nameof(Value), defaultBindingMode: BindingMode.TwoWay);
nameof(Value), defaultBindingMode: BindingMode.TwoWay, enableDataValidation: true);
public T? Value
{
@@ -485,6 +485,15 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
set => this.SetValue(CommandParameterProperty, value);
}
protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)
{
if (property == ValueProperty)
{
DataValidationErrors.SetError(this, error);
}
}
private void InvokeCommand(object? cp)
{
if (this.Command != null && this.Command.CanExecute(cp))