views:

379

answers:

1

I have a set of data objects that I am using for databinding that implement the INotifyPropertyChanged interface and I'm trying to figure out what to do with properties of complex type.

If I have something like


class C {
 private string text;
 public string Text {
  get { return text; }
  set {
   if(Text != value) {
    text = value;
    OnPropertyChanged("Text");
   }
  }
 }
}

I know what to do, but what if the property is mutable, presumably I should be notifying of changes to the type as well.

If the property itself implements INotifyPropertyChanged, presumably I can handle that event and bubble it up, but should I be doing the same if the raises a ListChangedEvent (say it is an IBindingList)?

This is .NET 2.0 so no dependency properties etc. allowed.

+1  A: 

If you have a property that exposes a complex type, you do not need to raise the PropertyChanged event when a property on the complex type changes, only when you change the instance to the complex type. The complex type should raise it's own PropertyChanged event when one of it's properties change (you should not have to bubble the event to the parent object).

To reiterate, you should only raise the PropertyChanged event when the value of a property changes, not when child properties change. The example code you provided is what all your property sets should look like.

Brian