Unfortunatelly Silverlight does not allow to set a UpdateSourceTrigger on the Binding. Therefore when using a TextBox the value of a twoway bound property only changes after the textbox looses the focus.

XML:
  1. <TextBox x:Name="Description"
  2.     Text="{Binding Path=Description, Mode=TwoWay}" />

This is not the kind of behavior I was looking for when I designed a small tool that should filter a list on the fly. Of course it should update the list on every key-stroke I make to get an immediate GUI response for our filtering.

On the web one only finds the "workaround" to manually make the control loose and gain focus on ever textchanged event. I think that is rather silly. Instead of using that workaround I used the following method:

  • Switch to OneWay Binding
  • Manually set the property of my object in the TextChanged event

The resulting XAML looks like this:

XML:
  1. <TextBox x:Name="Description"
  2.     Text="{Binding Path=Description, Mode=OneWay}"
  3.     TextChanged="Description_TextChanged" />

And the code-behind like this:

C#:
  1. private void Description_TextChanged(object sender, TextChangedEventArgs e)
  2. {
  3.     Filter.Description = ((TextBox)sender).Text;
  4. }

It's that simple. ;)

Post to Twitter Tweet this