文本框不允许我输入小数 [英] TextBox Won't Allow me to enter in a decimal
本文介绍了文本框不允许我输入小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在文本框中输入数字,但它不允许我输入十进制值.请问这是为什么?
I can Enter Numbers into the text box but it won't allow me to enter decimal values. May I ask why is this?
<TextBox Text="{Binding SebAmountPer, Mode=Twoway, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="2" TextWrapping="Wrap"/>
public decimal? SebAmountPer
{
get
{
return _seb.SEBAmountPer;
}
set
{
_seb.SEBAmountPer = value;
OnPropertyChanged("SebAmountPer");
OnPropertyChanged("SebTotal");
}
}
推荐答案
一种廉价的解决方法(如果您仍想保留内置验证并绑定到可空属性),是添加一个小的 绑定内的延迟
.这允许您实际输入一个小数"点,并在延迟"之后绑定,然后评估该值是否正确.
A cheap work-around (if you still want to keep the built-in validation and binding to a nullable property), is to add a small Delay
within the binding. This allows you to actually enter in a 'decimal' point, and after the 'delay' it binds, then evaluates the value as correct.
示例:
<TextBox Text="{Binding SebAmountPer, UpdateSourceTrigger=PropertyChanged, TargetNullValue='', Delay=350}" Height="75" Width="300" TextWrapping="Wrap"/>
这篇关于文本框不允许我输入小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文