I\'m creating a WPF application using MVVM. I have a textbox, which is bound to a property in my ViewModel of type double
with a default value of 0.0. If I now ente
You can try following solution. Firstly you should declare DoubleProperty as Nullable:
public double? DoubleProperty { get; set; }
Then create converter class implemented IValueConverter. It can looks like this:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double result;
if(!double.TryParse((string)value, out result))
{
return null;
}
return result;
}
Finally, you can use it:
xmlns:converter="clr-namespace:[TestApplication]"
Now, if user typed wrong values - DoubleProperty will be null.