1
votes

I implemented custom validation rules to use with TextBoxes in my WPF project. I have the following problem:

If, for example, I have a textbox for entering double values, after validation errors (e.g. for typing "30.0" I have to get a validation error when text is "30.") the validation / binding mechanism converts double representation of integer numbers ("30.0") to int representation ("30"). If I keep the validation rules but return always ValidationResult.ValidResult or remove the validation rules, the value does not change and remains "30.0".

How can I fix it / workaround it?

1
Please post some code (binding, property, and validation). What happens when the textbox is empty? - paparazzo

1 Answers

1
votes

You can control when the binding fires. If it happens on each keystroke, then you'll have a problem with the invalid intermediate 30. case, as you describe.

You might like to look at adding UpdateSourceTrigger=LostFocus to your Binding.

There's some more information here: http://msdn.microsoft.com/en-us/library/ms754356.aspx