The TextBox control updates the Text binding source only when it looses focus.
When you are writing in a TextBox and you press a button in the ApplicationBar, the focus not changes and your MVVM property doesn't update.
The workaround is to force the binding update like this:
var focusedElement = FocusManager.GetFocusedElement();
var focusedTextBox = focusedElement as TextBox;
if (focusedTextBox != null)
{
var binding = focusedTextBox.GetBindingExpression(TextBox.TextProperty);
if (binding != null)
binding.UpdateSource();
}
Hi,
RispondiEliminathis solution is valid for WindowsPhone and Windows 8?
Hi Daniele,
Eliminait works only in WP. The "GetBindingExpression" is missing in Win8. You can use this workaround:
http://www.familie-smits.com/post/2012/07/29/UpdateSourceTrigger-in-WinRT.aspx