How can I force my objects DataContext bindings to update? I'm using an event on a grid, and binding updates are not being processed before my event fires.
Any cheap tricks to get around this? In the end I can always do things the old manual way of getting the values from my textboxes and updating my object, but it'd be nice to have binding do it for me.
UPDATE
My grid contains two textboxes. If a user clicks on the grid (MouseButtonUp event) then I save the changes. But in my MouseButtonUp event handler, the datacontext is not up to date yet. I'd imagine it's because a text box only updates when focus is lost.
You can force an update of the source a binding by calling the UpdateSource() methond on on the binding. Try adding it to the MouseButtonUp event handler just before saving.
Like so:
BindingExpression binding = FirstTextBox.GetBindingExpression(TextBox.TextProperty)
if (null != binding) binding.UpdateSource();
You can find more information about this on MSDN: http://msdn.microsoft.com/en-us/library/system.windows.data.bindingexpression.updatesource(VS.95).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With