Silverlight 3 puts the ICollectionView interface to some serious use and brings us the CollectionViewSource class, which provides a view on top of the data collection, meaning you can sort, filter or group your items within your view, without actually changing the underlying data. One artifact, coming with the class, is the IsSynchronizedWithCurrentItem property, which enhances the collection with a notion of a currently selected item. When Selector’s IsSynchronizedWithCurrentItem property is set to true, all other controls, bound to the same collection, are kept in sync with the selected item. Silverlight’s implementation is a bit different than WPF’s. You can’t set IsSynchronizedWithCurrentItem property to true by yourself, the value is determined from your Items source. If it implements the ICollectionView interface, then it’s going to be synchronized, unless explicitly turned off (with setting the property to false).
For this example, I created three ListBoxes, all bound to the CollectionViewSource. Two of them are kept in sync, the third one is not because it’s IsSynchronizedWithCurrentItem property is set to false. I put up a few additional TextBlocks, bound to other item properties, to show the synchro-magic going on behind all this.
There’s more to ICollectionView interface, but that’s also another post…
Run the application online
Source code below: