-
Hi all, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
The NumberBox provides a NumberFormatter that can be used to alter the value within the NumberBox. Although there are built-in formatters available, creating a custom class that implements both the INumberFormatter2 and INumberParser interfaces may be necessary to achieve the specific functionality you described. This would enable you to check for NaN input values and replace them with a different default value, such as 0. |
Beta Was this translation helpful? Give feedback.
-
@Trix07 I would have thought it would be fairly common to want to default NaN to 0? After after couple of months of developing a tool which makes heavy use of the number box I too just realised that if a number box loses focus without any text the values in the view model will result in NaN causing exceptions (as it was not a case I expected I needed to handle). I don't mind the 3rd validation mode potentially suggest it is |
Beta Was this translation helpful? Give feedback.
You're right, I wasn't aware of that! Sorry for being misleading.
There is an alternative solution that involves creating a custom
IValueConverter
that operates on the same principle. This converter returns 0 if the value passed to it is either NaN or null. You can then use this converter when binding the NumberBox value to the Slider value.By using this approach, the NumberBox can still be empty while the Slider will default to 0. However, if it is necessary for the NumberBox to never be empty, then perhaps try to do the validation on the
ValueChanged
event.