logeeks
logeeks

Reputation: 4979

observablecollection question

I have a class/structure like the one given below

public class FileDetails { public FileDetails() { }

    public PrintFile PrintFileDetails { get; set; }
    public Boolean IsSelected { get; set; }
    public DateTime UploadTime { get; set; }
    public long FileSize { get; set; }
    public UploadTypes TypeOfUpload { get; set; }
    public DateTime DownloadStartTime {get;set;}
    public DateTime DownloadEndTime {get;set;}
    public bool ShouldDownload{get;set;}

}

In the above snippet PrintFile is defined in a XSD. I am planning to deploy this structure inside a ObservableConnection. If I implement NotifypropertychangedFileDetails will the items under PrintFileDetails also able to reap benefits of INotifypropertychanged. I believe i cannot implement the INotifyPropertyChanged as it is shared among other programmers.

Upvotes: 1

Views: 344

Answers (1)

dthorpe
dthorpe

Reputation: 36062

No, each object must implement INotifyPropertyChanged itself. The PrintFile object does not benefit from the fact that the FileDetails object implements an interface.

Also, if you are generating these classes from an XSD, you can tell the generator to generate the classes with INotifyPropertyChanged implementation automatically using the /enableDataBinding command line switch on XSD.EXE.

Footnote: Putting objects that implement INotifyPropertyChanged into an ObservableCollection won't have any magical effects. Changes made to the objects in the collection will not fire the collection's PropertyChanged event (unless you write the code to do so). The collection's PropertyChanged event only fires if a property of the collection object changes.

In most cases, you're using an observable collection because you want to data bind it to WPF or Silverlight UI elements and you want the UI to update itself automatically when the data changes. The data binding system will notice if the objects in the collection implement IPropertyNotifyChanged and will attach to the PropertyChanged events automatically so that the UI will know when the data changes.

Upvotes: 5

Related Questions