Skip to main content

Handling collection-changed events

The following example demonstrates how to subscribe to the CollectionChanged event of the DataGridCollectionView.SortDescriptions collection's INotifyCollectionChanged interface implementation to be notified when sorting applied to a grid's columns changes.

  protected override void OnInitialized( EventArgs e )
{
base.OnInitialized( e );
DataGridCollectionView view = this.OrdersGrid.ItemsSource as DataGridCollectionView;
( ( INotifyCollectionChanged )view.SortDescriptions ).CollectionChanged +=
new NotifyCollectionChangedEventHandler( this.SortCollectionChanged );
}
private void SortCollectionChanged( object sender, NotifyCollectionChangedEventArgs e )
{
Debug.WriteLine( "Sort changed" );
}