Skip to content

Fix numericupdown preview input#4563

Open
rtmongold wants to merge 4 commits intoMahApps:developfrom
rtmongold:fix-numericupdown-preview-input
Open

Fix numericupdown preview input#4563
rtmongold wants to merge 4 commits intoMahApps:developfrom
rtmongold:fix-numericupdown-preview-input

Conversation

@rtmongold
Copy link

Fixed an issue where the NumericUpDown control did not support keyboard entry of culture-specific negative signs. Cultures such as Norwegian (nb-NO) use U+2212 (−) as their negative sign rather than the standard ASCII hyphen-minus (-). This caused any attempt to enter a negative number via keyboard or paste to be blocked or lost.

Three changes were made to NumericUpDown.cs:

  • OnPreviewTextInput - converts ASCII - to the culture's actual negative sign before building the full text and validating, ensuring the correct character is inserted into the text box
  • TryGetNumberFromText - updated the regex to include the culture's actual negative and positive signs so that U+2212 is correctly matched during text extraction
  • ValidateText - normalises culture-specific negative and positive signs back to ASCII equivalents before calling double.TryParse, ensuring parsing succeeds regardless of the culture's sign characters

Unit test
A unit test should verify that a NumericUpDown configured with Norwegian culture (nb-NO) correctly accepts U+2212 (−) as a negative sign both via keyboard entry and paste, and that the resulting value is correctly parsed and stored as a negative number.

Additional context
This issue affects any culture where CultureInfo.NumberFormat.NegativeSign is not the standard ASCII hyphen-minus (-), including but not limited to Norwegian (nb-NO). The fix is culture-agnostic and will correctly handle any culture's negative and positive sign characters.

Closes Issue #4560

…+2212)

- Updated OnPreviewTextInput to convert ASCII '-' to culture's actual negative sign before validation
- Updated TryGetNumberFromText regex to include culture-specific negative and positive signs
- Updated ValidateText to normalise culture-specific signs to ASCII before double.TryParse
Remove of accidental lines at the end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant