When doing databinding does one have to implement INotifyPropertyChanged on the datacontext in WPF?
+4
A:
No. If you don't intend for your object's properties to change, or you don't mind if the UI doesn't reflect those changes, there's no reason to implement INotifyPropertyChanged.
Further, if your object derives from DependencyObject and its properties are dependency properties, data binding will work without INotifyPropertyChanged.
Matt Hamilton
2010-03-13 11:14:02
but my object's properties do change and I do mind when my UI doesn't reflect those changes. So which is better to use, INotifyPropertyChanged or dependency object?
Tony
2010-03-13 11:15:28
INotifyPropertyChanged is a bit simpler IMHO, and doesn't require you to derive from a certain class, so you have the option of keeping your own class hierarchy.
Matt Hamilton
2010-03-13 11:42:48
@Matt I agree. INotifyPropertyChanged is simpler to implement.
Tony
2010-03-13 11:52:18
A:
If you are interested in a comparison between INotifyPropertyChanged and DependencyProperties you can find a good article here.
In general, if the object supports DependencyProperties, try to avoid INotifyPropertyChanged.
Maurizio Reginelli
2010-03-13 12:18:19
A:
Also, if you are working with ObservalbeCollections, INotifyPropertyChanged is implemented in it, if i'm not mistaken
djerry
2010-03-15 10:57:26