Reputation: 231
I have a numeric up down
like this:
<NumericUpDown Value="{Binding Samples}" ShowButtonSpinner="False" ParsingNumberStyle="Integer"/>
Then I use this on the MainWindow.axaml.cs:
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Key == Key.Enter) // includes Key.Return
Focus();
}
This makes the Input lose focus when the Return
key is pressed.
if I type '100' into the field and press return, it accepts the value, like I would expect.
if I type '100.0' or any invalid string the field does not loose focus when pressing return
. In this case I'd like the input to be reset to whatever it was before the user started typing.
Do I need to write my own validator and call it while the user is typing?
Upvotes: 0
Views: 39