I’m currently encountering this issue while programming Metro, but I’m sure it applies to WPF, Silverlight and possibly even WinForms.
I have a databound TextBox and a method attached to the LostFocus event of the TextBox. When it loses focus, I want the code behind to trigger a save function in order to persist the data. The problem is that the LostFocus-event triggers before the business object is updated from the GUI through TwoWay databinding.
What is the best way to handle this? Is there some way to force update of the databinding from the LostFocus method (would probably be platform-specific)?
It sounds like you’re wanting to do some business logic instead of having the GUI update the textbox. I would set the
Textboxto only beBindingMode.OneWay, so that when the business object is changed the textbox is updated properly.Then in the Lostfocus event (again wpf, but I think you’ll get the idea):
This way you’re in full control of when the object gets updated, and can apply your business rules.