Don Hasenohrl

I've got a two-way binding set on the text property of a text box. The binding has a validation rule.

I don't want to set the UpdateSourceTrigger to PropertyChanged because I don't want the validate rule to fire for every key stroke.

An UpdateSourceTrigger value of LostFocus doesn't work well for me either since I want the update to occur even when I leave the focus scope.

What I'd really like would be to update the source on KeyboardLostFocus. Is there anyway I can mimic this



Re: Windows Presentation Foundation (WPF) Need Two-way binding to update source on keyboard lost focus

Josh Smith

Call UpdateSource() on the Text property's BindingExpression when KeyboardLostFocus fires on the TextBox. You might need to set the Binding's UpdateSourceTrigger to 'Explicit' for that to work.




Re: Windows Presentation Foundation (WPF) Need Two-way binding to update source on keyboard lost focus

Don Hasenohrl

I tried that solution but then the update occurs even if you're just tabbing through the text box without making a change. I only want the update to occur if the value was modified on KeyboardLostFocus.



Re: Windows Presentation Foundation (WPF) Need Two-way binding to update source on keyboard lost focus

Yi-Lun Luo - MSFT

You can get a copy of the text when the TextBox got focus, and compare it with the new text value when losing focus.