I have to create a form in which the user must input his age. I would like to use a numeric keyboard:
To me the simple solution is just to add a TextChanged handle to the Entry (this is UI specific code so does not break MVVM)
Then in code behind
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
//lets the Entry be empty
if ( string.IsNullOrEmpty(e.NewTextValue) ) return;
if ( !double.TryParse(e.NewTextValue, out double value) )
{
((Entry) sender).Text = e.OldTextValue;
}
}
Change in int.Parse if need an integer