From 4340052cae4e98fe05ff514f357bbab4777ff65a Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 12 May 2023 14:12:40 +0200 Subject: [PATCH] fix incement / decrement when value was null --- src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs b/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs index 885a8af5d1..e97692b255 100644 --- a/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs +++ b/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs @@ -659,7 +659,9 @@ namespace Avalonia.Controls } else { - result = Minimum; + // if Minimum is set (i.e: Minimum is greater than decimal.MinValue) we set value to Minimum on Increment. + // otherwise we set value to 0. It ill be clamped to be between Minimum and Maximum later, so we don't need to do it here. + result = Minimum > decimal.MinValue ? Minimum : 0; } SetCurrentValue(ValueProperty, MathUtilities.Clamp(result, Minimum, Maximum)); @@ -678,7 +680,9 @@ namespace Avalonia.Controls } else { - result = Maximum; + // if Maximum is set (i.e: Maximum is smaller than decimal.MaxValue) we set value to Maximum on decrement. + // otherwise we set value to 0. It ill be clamped to be between Minimum and Maximum later, so we don't need to do it here. + result = Maximum < decimal.MaxValue ? Maximum : 0; } SetCurrentValue(ValueProperty, MathUtilities.Clamp(result, Minimum, Maximum));