/// <summary> /// INotifyCollectionChanged.CollectionChanged handler for updating DataGrid.SelectedItems when the source list changes /// </summary> private static void UpdateDataGridsOnSourceCollectionChanged(object source, NotifyCollectionChangedEventArgs collectionChangedArgs) { DataGridsAndInitiatedSelectionChange sourceListInfo = DataGridMultipleSelection.selectedItemsSources[source.GetHashCode()]; // For each DataGrid that is bound to this list, is alive, and did not initate selection changes, update its selection sourceListInfo.InitiatedSelectionChange = true; IList sourceList = source as IList; Debug.Assert(sourceList != null, "SelectedItemsSource must be of type IList"); DataGrid dataGrid = null; foreach (WeakReference dataGridReference in sourceListInfo.BoundDataGridReferences) { if (dataGridReference.IsAlive && !DataGridMultipleSelection.GetInitiatedSelectionChange(dataGridReference.Target as DataGrid)) { dataGrid = dataGridReference.Target as DataGrid; UpdateDataGrid(dataGrid, sourceList, collectionChangedArgs); } } sourceListInfo.InitiatedSelectionChange = false; }