How do I style an Avalonia NumericUpDown control integer-only?

500 Views Asked by At

Every time I click the Up or Down button of an Avalonia NumericUpDown control a period with a zero gets added to the value, i.e. it increases as 2.0, 3.0, 4.0 etc. instead of 2, 3, 4 (which would be the desired behaviour).

The decimal point and the zero only disappear as soon as the application window loses focus and appear again once I click decrease/increase again.

How do I possibly change this?

An answer to a similar question suggests setting the DecimalPlaces property to zero but the Avalonia implementation of the control appears lacking this property.

2

There are 2 best solutions below

0
Tarazed On BEST ANSWER

Just specify the incrementation level, it should be automatic.

<NumericUpDown Increment="1" />
0
SLenik On

Unfortunately, Increment property cannot prevent user from entering the fractional part of a number from keyboard =(

If you want allow the user to enter only integers, use this combination of properties:

<NumericUpDown FormatString="N0"
               ParsingNumberStyle="Integer" />

ParsingNumberStyle is for blocking user to enter decimal point, and FormatString is for displaying value without fractional part while editing from keyboard.