Wednesday, April 1, 2015

Solution for textBox text change not updating the view model/model

<TextBox Name="textBox1"
      Height="23" Width="463"
      HorizontalAlignment="Left" 
      Margin="12,12,0,0"   
      VerticalAlignment="Top"
      Text="{Binding OriginalText, UpdateSourceTrigger=PropertyChanged}" /> 
The TextBox.Text property has a default UpdateSourceTrigger value of LostFocus. This means if an application has a TextBox with a data-bound TextBox.Text property, the text you type into the TextBox does not update the source until the TextBox loses focus (for instance, when you click away from the TextBox).
If you want the source to get updated as you are typing, set the UpdateSourceTrigger of the binding to PropertyChanged. In the following example, the Text properties of both the TextBox and the TextBlock are bound to the same source property. The UpdateSourceTrigger property of the TextBox binding is set to PropertyChanged.

No comments:

Post a Comment