PropertyChangedBase, BindableCollection and IDispatcher

PropertyChangedBase

It is common in WPF/Silverlight applications to need to implement INotifyPropertyChanged. In order to cut down on the repetitiveness of implementing this interface and for the framework's own use, Caliburn supplies developers with PropertyChangedBase, which lives in Caliburn.Core. In addition to implementing the INotifyPropertyChanged interface, it passes all event publication through to Caliburn's Dispatcher. This ensures thread-affinity of event publication. Essentially, you can set a property in a subclass on a backgroung thread, but Caliburn will insure that the event is always raised on the UI thread. This frees the developer from having to think about thread marshaling solely for the purpose of setting ViewModel properties which may be bound to the UI.

BindableCollection

The same problems that arise with change notification and threading when setting properties on a ViewModel also occur when adding/removing items from an ObservableCollection<T> that is databound. To solve these problems, Caliburn supplies BindableCollection<T> which inherits from ObservableCollection<T> and fixes the the threading problems by using Caliburn's dispatcher. This class, along with its parallel interface IObservableCollection<T>, live in Caliburn.PresentationFramework.

IDispatcher

Caliburn supplies developers with an abstraction of the WPF/Silverlight dispatcher called IDispatcher which is located in Caliburn.Core. The default implementation of this interface, DispatcherImplementation, located in Caliburn.PresentationFramework wraps the underlying dispatcher provided by the platform and adds some additional behavior, such as a consistent way of doing background processing and smart UI thread marshaling. For advanced scenarios, you may wish to write your own implementation of IDispatcher and configure it with the Core. Additionally, Caliburn provides a second implementation (WPF only) called BatchingDispatcher. This implementation is designed for semi-high update throughput scenarios. It holds a queue of events which should be raised on the UI thread and batches those events to the UI thread at a specified time interval. If you have extreme high-frequency updates, you might want to use a snapshot model instead of the batcher.

Last edited Oct 23, 2009 at 7:55 PM by EisenbergEffect, version 7