If you have installed .NET 4.5 or later, you can apply behavior up to 4.5
System.Windows.FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false;
In .NET 4.5, you can no longer enter a separator character (comma or period) with UpdateSourceTrigger = PropertyChanged by default.
You may also have a delay:
<TextBox Width="100" Margin="10" Text="{Binding DoubleField, UpdateSourceTrigger=PropertyChanged,Delay=500, ValidatesOnDataErrors=True}">
And another way is to use IValueConverter:
public class DoubleToPersistantStringConverter : IValueConverter { private string lastConvertBackString; public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (!(value is double)) return null; var stringValue = lastConvertBackString ?? value.ToString(); lastConvertBackString = null; return stringValue; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (!(value is string)) return null; double result; if (double.TryParse((string)value, out result)) { lastConvertBackString = (string)value; return result; } return null; } }
check this link: Double field snapping with check
But I think the best way is to set UpdateSourceTrigger to LostFocus .
source share