Page view counter

How do you know INotifyPropertyChanged is Working

Today I had the great enjoyment to make two presentations to the Microsoft Health and Life Sciences Conference here in Atlantic City.

While showing DataBinding, I became interested in demonstrating the effects of INotifyPropertyChanged, The basic mechanism is this; you add a PropertyChangedEventHandler to your business object and each time you set a bound property you invoke that event, passing in a reference to the business object and an instance of PropertyChangedEventArgs initialized with the name of the property

PropertyChanged

The bound Silverlight controls will respond to this event and update themselves to the new value. But how to test this?

We tried making a new browser, but no go; we suspected (correctly) that the UI was pointing to two different objects. I proved this to myself by modifying the constructor to generate a random number and store it in a member variable, which I display.

AddedID

 

When you attempt to create two views on the data (by hitting control N on the browser or by copying the URL to a new tab) you generate a new object as you can see by the new ID.

 

SideBySide

 

To ensure that we're seeing the UI update in response to changes to the same object, it is easiest to just add two new rows, one that shows the value of IsPublished and the other that shows Quantity on Hand. When you change the original, the duplicate should be informed through the event.

ReflectionOfBinding

 

We can now run the program again and when we change the isPublished or QuantityOnHand properties, we should see that immediately reflected in the second control. Turn off the notification and the reflection should stop.

 

ReflectedBindingRunning

Published Wednesday, April 23, 2008 5:45 PM by jesseliberty
Filed under:

Comments

# Dew Drop - April 24, 2008 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop - April 24, 2008 | Alvin Ashcraft's Morning Dew

Thursday, April 24, 2008 11:21 AM by Dew Drop - April 24, 2008 | Alvin Ashcraft's Morning Dew

# re: How do you know INotifyPropertyChanged is Working

Hi,

I ran into problems when trying to dynamically load a xap which uses a data binding (it's all working right when it's all compiled together in the first place).

To make a long story short - the PropertyChanged event is null and I can't invoke it.

What could be the reason for that?

Thanks, Tzahi.

Sunday, July 13, 2008 10:28 AM by tzahis

# re: How do you know INotifyPropertyChanged is Working

thats really great property..!!!

one another property is :"OneTime"

OneTime updates the target property only when the application starts or when the DataContext undergoes a change.

:)

Wednesday, March 18, 2009 2:40 AM by gaumz04

# Mini-Tutorial – Element Binding

What It Is With element binding, it is now possible to bind the value of one object in your UI directly

Wednesday, July 22, 2009 12:54 AM by Jesse Liberty - Silverlight Geek

# Mini-Tutorial – Element Binding

What It Is With element binding, it is now possible to bind the value of one object in your UI directly

Wednesday, July 22, 2009 1:52 AM by Microsoft Weblogs