TextBox Binding TwoWay Doesn't Update Until Focus Lost WP7
I assume your Save button is an ApplicationBarButton (not a normal button). For normal buttons it will just work because they take focus and hence the data-binding will kick in.
For ApplicationBarButtons on the phone it's a little different because they don't take focus away from the client app. To ensure the data-binding kicks in when your Save button is clicked, you can add the following code in your handler:
object focusObj = FocusManager.GetFocusedElement();
if (focusObj != null && focusObj is TextBox)
{
var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty);
binding.UpdateSource();
}
Download Charles Petzold's free book Programming Windows Phone 7. On page 387 he talks about how to do this.
Basically, set the UpdateSourceTrigger
property of the Binding
to Explicit
. Then, in the TextBox
's TextChanged
callback, update the Binding source.
try to set UpdateSourceTrigger
property to 'PropertyChanged'
like this
Property="{Binding PropertyBinding, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
You can use the UpdateTextBindingOnPropertyChanged
behavior from the Prism Library for WP7 to update the bound value when the text changes instead of on lost focus.