views:

32

answers:

1

Im a bit confused. I dont understand what code is actually is executed when I implement INotifyPropertyChanged interface. As i imagine the chain goes like this:

  • My class impliments INotifyPropertyChanged=>
  • Every property`s setter calls
    NotifyPropertyChanged method=>
  • PropertyChangedEventHandler
    invokes=>???

And i wonder what code makes my control rerender. Thanks.

+1  A: 

The control will subscribe to the event when it binds. When you raise the event, the control will check whether the property that's been changed is one of the ones it cares about. If it is, it will fetch the new value of the property, and rerender itself.

Of course, the handler doesn't have to be to do with controls rerendering - they can do anything. It's just a way of saying, "Hey, property X has changed its value... if you care about that, do something." You can add your own handlers very easily, just like any other event handlers.

Jon Skeet
"The control will subscribe to the event when it binds" - For example label1.DataBindings.Add(new Binding("Text", someObject, "Name"));?
Vladimir Nani
@Vladimir: Presumably so, yes. I don't know the internals of *exactly* where it happens, but that's the general idea.
Jon Skeet

related questions