3

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 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I found that: FormatString="N0" with or without ParsingNumberStyle="Integer" rounds. ParsingNumberStyle="Integer" without FormatString="N0" truncates. Neither FormatString="N0" nor ParsingNumberStyle="Integer" physically stops the user entering a decimal point. However, if the user focuses another control after entering the decimal number, the rounding/truncation will then be shown in the NumericUpDown.
Greetings, @SimonOR! Please specify the version of AvaloniaUI library in which you see this behavior. I've written this post for AvaloniaUI 0.10. Maybe current AvaloniaUI 11 has changed this behavior.
Hello @SLenik! Yes, my investigation was in version 11.0.x of Avalonia UI.
1

Just specify the incrementation level, it should be automatic.

<NumericUpDown Increment="1" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.