方法一:
public class DecimalConverter:IValueConverter
{
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)
{
return value.ToString().EndsWith(".") ? "." : value;
}
}
<Window.Resources>
<localHelper:decimalConverter x:Key="decimalConverter" />
</Window.Resources>
<TextBox Text="{Binding Qty,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource decimalConverter}}" />
方法二:
在 public partial class App : Application 里重写OnStartup方法
protected override void OnStartup(StartupEventArgs e)
{
//设置一个值,此值指示数据绑定 TextBox 是否应显示与源的 Text 属性值一致的字符串 为false
System.Windows.FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false;
base.OnStartup(e);
}