I'm trying to come up with a better approach for my other problem:
Avalonia: Get Numeric UpDown to parse the text on lost focus
In short: I'd like a TextBox that ignores non-numeric characters while typing.
If I am using numeric updowns like this:
<NumericUpDown Value="{Binding Samples}" ParsingNumberStyle="Integer" ShowButtonSpinner="False"/>
The user can type in non-numeric characters, which makes the box reset to it's former value, when I click outside of it. However pressing Return does not work unless the text is a proper integer (see link above).
I guess I could use
OnMyValueChanging(int oldValue, int new Value)
{
//validate
}
However the value is an integer, so I can't verify it while typing. I could use a regular TextBox, but then I'd have to write the OnValueChanging for every occurence of my numeric inputs. Maybe I can use Styles for that? But I don't know how to point to a project-wide function, that can be shared across multiple view models.