I have an Entry which is binded two way with nullable decimals and has numeric keyboard. Everything is ok except I cannot use decimal point. Whenever I press . (dot) from keyboard, UI does not accept it. Do you guys have any idea? Online search did not help me. Thanks. BTW, I use Android Emulator.
Asked
Active
Viewed 799 times
2 Answers
0
I found out that if I change property from nullable to non-nullable (i.e decimal? to decimal) then UI accepts decimal point. Do you guys have any idea why? Why UI does not allow to enter decimal point when the binding property is nullable?

Kevin S
- 33
- 1
- 6
-
I have solved the issue but underline issue still remains unanswered. Why UI does not allow to use decimal point for Entry when it is binded with decimal? (nullable) where as when binded with decimal (non-nullable), a decimal point is allowed. Is there any xamarin dcouments that can explain this behavior ? Thanks. – Kevin S May 28 '20 at 20:06
0
This is because the value is not recognized with a defined type while it is incomplete (editing).
You can use a converter (String to double) like this:
>
public class DoubleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return null;
return (double)value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return null;
string stringValue = value as string;
if (string.IsNullOrEmpty(stringValue))
return null;
double dbl;
if (double.TryParse(stringValue, out dbl))
{
if(dbl == 0)
{
return null;
}
return dbl;
}
return null;
}
}
Reference:
https://forums.xamarin.com/discussion/60719/xamarin-forms-binding-nullable-double-to-entry

Filipe Piletti Plucenio
- 704
- 10
- 25