Hello All,
I have a MaskedEditorTool whose "Text" field is two-way bound to a DateTime. The MaskedEditorTool is the source and I provide a value converter to convert between string and DateTime using a format of "MM-dd-yyyy-HH\\h-mm\\m-ss\\s". The problem with this arrangment is that every keystroke in the editor tries to update the target. While I'm in the process of typing in a date / time, the string in the editor does not always represent a valid date / time. This causes my converter to throw an exception, and the world ends. I would rather suppress data binding updates until edit mode has ended. Is this possible?
Thanks,
Dave
Basically a TwoWay Binding will push a value into the source based upon the UpdateSourceTrigger. That value defaults to the default updatesourcetrigger for the target property which for just about every property in the WPF framework (with the exception of things like TextBox.Text) is PropertyChanged so as the property changes it will update the source. To change when the Binding updates the source you would set the UpdateSourceTrigger on the Binding to something else. You could use LostFocus but be aware that that means logical focus so if you shift focus to an element in a different focus scope (e.g. a menu, toolbar, ribbon or even another form) the element will not have lost logical focus and therefore the binding won't update the source.