简体   繁体   English

WPF DataGridTextColumn绑定不接受小数

[英]WPF DataGridTextColumn binding doesn't accept decimals

I don't understand what the problem could be. 我不明白问题是什么。 The binding is on a Decimal property. 绑定在Decimal属性上。 Here is the XAML: 这是XAML:

<DataGridTextColumn Header="Price" Binding="{Binding Price, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged} Width="*"/>

I literally cannot type the '.' 我字面上不能输入'。' character. 字符。 Why would it stop me from typing that character and how do I tell it to let me do so. 为什么它会阻止我输入那个字符,我怎么告诉它让我这样做。

I tried doing a string format like this: 我试着像这样做一个字符串格式:

<DataGridTextColumn Header="Price" Binding="{Binding Price, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:n2}} Width="*"/>

But this doesn't solve my problem because all it does is append ".00" to the end of whatever I type. 但这并没有解决我的问题,因为它所做的就是将“.00”附加到我输入的任何内容的末尾。

All I need is permission to type the period. 我只需要输入句号即可。

UPDATE: 更新:

I was directed here . 我被引导到这里 I removed the UpdateSourceTrigger property and this made it possible for me to type a '.'. 我删除了UpdateSourceTrigger属性,这使我可以输入'。'。 I do not have 4.5 Beta installed and my localization settings are correct. 我没有安装4.5 Beta,我的本地化设置是正确的。 So now my question is how do I get the DataGridTextColumn to allow me to type '.' 所以现在我的问题是如何让DataGridTextColumn允许我输入'。' with an UpdateSourceTrigger property set? 是否设置了UpdateSourceTrigger属性?

UpdateSourceTrigger=PropertyChanged reevalutes the text on every keystroke. UpdateSourceTrigger = PropertyChanged重新评估每次击键时的文本。 A number that ends in a decimal point is invalid. 以小数点结尾的数字无效。 Change the UpdateSourceTrigger to LostFocus (same as removing it) or try to type the '.' 将UpdateSourceTrigger更改为LostFocus(与删除它相同)或尝试键入'。' while you have other digits after it. 而你之后还有其他数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM