My application implements a simple Calculation Chain, as spreadsheets do. It has a TextBox into which the user types some numerical values and as soon as it is edited, the code proceeds to update all the dependent fields.
My scarce experience with TextBox tells me that an event can be triggered each time the user clicks a character. This behavior is not good: Suppose the person types the value "1234": the calculation chain would be performed for "1", next for "12", then for "123" and finally for "1234".
I need a way to know when the editing ended. Maybe the rectangle could become blue upon Enter, like those in DataGrid. The user should be able to leave with the Tab key or by clicking elsewhere.
Also: an empty TextBox is not the same thing as containing a zero! An empty TextBox's content should be recognized as undefined.
The question then is: What kind of control and ancillary functions do I need?
Anonymous User
18-Dec-2013It sounds like you only want to perform your calculation when the TextBox has LostFocus
In your view you will have
Then in your code-behind define that method
Alternatively, you can use a TwoWay binding and the default PropertyChangeTrigger on a TextBox should be LostFocus - so you should only get your property update when the user has moved away from the TextBox.
Note that this won't satisfy your hope of also handling it on the press of an Enter, as the TextBox would still have focus. To enable this also, extend it slightly