@@ -119,6 +119,12 @@ public class NumericUpDown : TemplatedControl
119
119
public static readonly StyledProperty < VerticalAlignment > VerticalContentAlignmentProperty =
120
120
ContentControl . VerticalContentAlignmentProperty . AddOwner < NumericUpDown > ( ) ;
121
121
122
+ /// <summary>
123
+ /// Defines the <see cref="DecimalPlaces"/> property.
124
+ /// </summary>
125
+ public static readonly StyledProperty < int > DecimalPlacesProperty =
126
+ AvaloniaProperty . Register < NumericUpDown , int > ( nameof ( DecimalPlaces ) , 2 ) ;
127
+
122
128
private IDisposable _textBoxTextChangedSubscription ;
123
129
124
130
private double _value ;
@@ -261,6 +267,15 @@ public double Value
261
267
}
262
268
}
263
269
270
+ /// <summary>
271
+ /// Gets or sets the number of decimal places to display in the up-down control.
272
+ /// </summary>
273
+ public int DecimalPlaces
274
+ {
275
+ get { return GetValue ( DecimalPlacesProperty ) ; }
276
+ set { SetValue ( DecimalPlacesProperty , value ) ; }
277
+ }
278
+
264
279
/// <summary>
265
280
/// Gets or sets the object to use as a watermark if the <see cref="Value"/> is null.
266
281
/// </summary>
@@ -620,7 +635,7 @@ private string ConvertValueToText()
620
635
/// </summary>
621
636
private void OnIncrement ( )
622
637
{
623
- var result = Value + Increment ;
638
+ var result = Math . Round ( Value + Increment , DecimalPlaces ) ;
624
639
Value = MathUtilities . Clamp ( result , Minimum , Maximum ) ;
625
640
}
626
641
@@ -629,7 +644,7 @@ private void OnIncrement()
629
644
/// </summary>
630
645
private void OnDecrement ( )
631
646
{
632
- var result = Value - Increment ;
647
+ var result = Math . Round ( Value - Increment , DecimalPlaces ) ;
633
648
Value = MathUtilities . Clamp ( result , Minimum , Maximum ) ;
634
649
}
635
650
0 commit comments