Where is my Binding UpdateSourceTrigger= PropertyChanged on WP7 Silverlight ?

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);
bindingExpression.UpdateSource();
}

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

You may also like...

2 Responses

  1. It acts immediately on all your garage concerns as quickly as possible.
    This article will take you through the steps to safely remove the hinge and roller assembly and replace the roller.

    Many home improvement stores carry Wayne Dalton parts and
    doors so they would have additional resources for you.

  2. Hulda says:

    Hi there, I desjre to subscribe for this blog to obtain hottest updates, therefoe where can i do it
    please help.

Leave a Reply

Your email address will not be published. Required fields are marked *