I accepted the Praetorian answer and made an extension class that inherits a TextBox , so you don't need to confuse your view code with this behavior.
C-Sharp :
public class TextBoxUpdate : TextBox { public TextBoxUpdate() { TextChanged += OnTextBoxTextChanged; } private void OnTextBoxTextChanged(object sender, TextChangedEventArgs e) { TextBox senderText = (TextBox)sender; BindingExpression bindingExp = senderText.GetBindingExpression(TextBox.TextProperty); bindingExp.UpdateSource(); } }
Visualbasic
Public Class TextBoxUpdate : Inherits TextBox Private Sub OnTextBoxTextChanged(sender As Object, e As TextChangedEventArgs) Handles Me.TextChanged Dim senderText As TextBox = DirectCast(sender, TextBox) Dim bindingExp As BindingExpression = senderText.GetBindingExpression(TextBox.TextProperty) bindingExp.UpdateSource() End Sub End Class
Then call this in XAML :
<local:TextBoxUpdate Text="{Binding PersonName, Mode=TwoWay}"/>
KyleMit Dec 02 '13 at 2:08 on 2013-12-02 02:08
source share