IObservableCollection and INotifyPropertyChanged
While working on the new installer for Geocortex Essentials, I spent a fair amount of time looking at Windows Presentation Foundation (WPF). One of the things that WPF does particularly well is data binding. Having said that, I discover that there seems to be an easy way and a hard way to do it. The easy way is to ensure that collections you wish to data bind to implement IObservableCollection and that objects within those collections implement INotifyPropertyChanged because the WPF data binding engine will exploit these constructs if they are available.
To see why this is a good thing, imagine a DataGrid bound to a simple array of simple objects. If you were to add an item to that array or modify an object within that array, the results would not be visible until you refreshed the data binding. If instead you were to use a DataGrid bound to an IObservableCollection containing objects implementing INotifyPropertyChanged, changes to that collection and objects within that collection will be reflected immediately within the DataGrid with no extra programming required. How simple is that? One further gem that I discovered was that it is possible for a WPF application to consume a Windows Communication Foundation service (WCF) and realize the service's collections as IObservableCollection containing INotifyPropertyChanged objects This makes it extraordinarily easy to create rich, distributed WPF applications.
Until next time...