Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

c# - WPF DataGridTextColumn binding doesn't accept decimals

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="*"/>

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.

UPDATE:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...