WTF! Where is the UpdateSourceTrigger= PropertyChanged on WP7 Silverlight? J
I got surprised when I saw that there was no PropertyChanged option on the UpdateSourceTrigger… All I could see was Default and Explicit…
The Default behavior works like our “LostFocus” from WPF, where the value is updated only when the control loses focus. This works most of the time, but there will be situations that you need the value to get updated as soon as the control values changes (equivalent to PropertyChanged).
To achieve this behavior you will need to do:
Set the UpdateSourceTrigger to Explicit
When you say that it is “explicit”, basically you will have to handle it…. Next step is to add one event handler to your bound control. On my sample it is a TextBox.
On the event handler comes the magic:
private void TextChangedUpdateTrigger(object sender, TextChangedEventArgs e)
TextBox txtbox = sender as TextBox;
BindingExpression bindingExpression = txtbox.GetBindingExpression(TextBox.TextProperty);
The code above sets the binding explicitly! Great!!(or not so if you know what I mean) Anyway, this will give you the “PropertyChanged” like behavior…
That’s it for now!
BTW I found this solution on the very nice free book
Programming Windows Phone 7 from Charles Petzold. Read the whole book or jump to page 387 to know about this issue in particular. J