WPF DataGridTextColumn绑定不接受小数 [英] WPF DataGridTextColumn binding doesn't accept decimals

查看:65
本文介绍了WPF DataGridTextColumn绑定不接受小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白这可能是什么问题.绑定位于Decimal属性上.这是XAML:

I don't understand what the problem could be. The binding is on a Decimal property. Here is the 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="*"/>

但这不能解决我的问题,因为它所做的只是将".00"附加到我键入的内容的末尾.

But this doesn't solve my problem because all it does is append ".00" to the end of whatever I type.

我所需要的只是输入句点的权限.

All I need is permission to type the period.

更新:

此处指示我.我删除了UpdateSourceTrigger属性,这使我可以键入.".我没有安装4.5 Beta,我的本地化设置正确.所以现在我的问题是如何获取DataGridTextColumn以允许输入.".设置了UpdateSourceTrigger属性?

I was directed here. I removed the UpdateSourceTrigger property and this made it possible for me to type a '.'. I do not have 4.5 Beta installed and my localization settings are correct. So now my question is how do I get the DataGridTextColumn to allow me to type '.' with an UpdateSourceTrigger property set?

推荐答案

UpdateSourceTrigger = PropertyChanged重新评估每次击键时的文本.以小数点结尾的数字无效.将UpdateSourceTrigger更改为LostFocus(与删除它相同)或尝试键入.".而后面还有其他数字.

UpdateSourceTrigger=PropertyChanged reevalutes the text on every keystroke. A number that ends in a decimal point is invalid. Change the UpdateSourceTrigger to LostFocus (same as removing it) or try to type the '.' while you have other digits after it.

这篇关于WPF DataGridTextColumn绑定不接受小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆