I was wondering if it is possible to change the time that a binding updates the controls that are bound to it. For instance, I’m working with a TextBox, which is updating every time a key is pressed, but I would like it to update when it loses focus instead.
Any ideas?
I was wondering if it is possible to change the time that a binding
Share
Well this surprises me because I thought the TextBox was the one control which held back its updating of the binding source until the focused moved elsewhere, a small test confirms this.
Anyhow, lets imagine that it does normally update on every key press or some control like it does.
A general solution would be to take “manual” control of source updating. You can do this with the
UpdateSourceTriggerproperty setting to “Explicit”. This means the source of the binding will only by updated when your code explicitly calls theUpdateSourcemethod on theBindingExpressionfor the binding with theTextPropertyof the “TextBox”.You could perform this explicit update then in an event handler for the “TextBox”
LostFocusevent.For Example, in an initial UserControl add this xaml:-
Now in the code-behind the event handler looks like this:-