question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NumericUpDown should accept null as Value

See original GitHub issue

Is your feature request related to a problem? Please describe. I have a form where “0” is a total valid value, but I want to make sure the user inserted this and does not use the “default” value provided by the system. In WPF I just left the field empty (‘null’) and checked if the field is not null on save

Describe the solution you’d like make Value nullable

Describe alternatives you’ve considered Create my own control

Additional context image Fields should be empty

If you are OK with this change, I can provide a PR for this.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
robloocommented, May 6, 2022

I just checked TextBox too. The Text property is still nullable even after the switch to nullable ref types. I’m very surprised it was stated this isn’t common. In fact every other input control i’m aware of supports this functionality.

2reactions
robloocommented, May 6, 2022

@danwalmsley There are many scenario where apps need to know if a user has/has-not made a selection. Zero in the case of a NumericUpDown is a valid number and is not enough to indicate no user-selection. This type of functionality is common in LOB apps where form field values are being entered. In fact every single control I am aware of has some way of keeping 'null/empty values for no user-selection.

When the NumberBox spec was widely discussed with Microsoft this was also a valid scenario. However double.NaN could be used to add this functionality. With the switch to decimal in Avalonia that was overlooked and it needs to be added back somehow.

There are two standardized ways of doing this:

  1. Add a nullable SelectedValue property along with Value. This is the strategy used in DatePicker where the underlying type doesnt support empty/null.
  2. In something like TextBox, null has historically been supported for this but string itself has an Empty state so can be used for this info as well. So these controls don’t need a special case and additional property because the underlying type supports it.
Read more comments on GitHub >

github_iconTop Results From Across the Web

make nullable Numeric up down c# - Stack Overflow
The controls uses a Value property which is of type decimal. As such, then decimal is not nullable so you can't set this...
Read more >
Thread: possible to keep empty value in numeric updown?
Hi, i would like to know is there possible to keep empty value in numeric updown my numeric updown should have the following...
Read more >
Initialize NumericUpDown with null in UI for WPF
Hi, By default if the Value property of the control is bound to a null value the NullValue will be shown. I recorded...
Read more >
Restriction in WPF NumericUpdown (UpDown)
The UpDown control accepts null values. When the Value is set to null, the UpDown control will show zero value by default. You...
Read more >
NumericUpDown and NULL values
I try to set a null value to the NumericUpDown control with the following code. Dim locNullAbleDecimal As Decimal? = Nothing numericUpDown.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found