private void OnItemCollectionSourceChangedSafe(NotifyCollectionChangedEventArgs e) { VerifySafe(); if (e.Action == NotifyCollectionChangedAction.Move) { } else if (e.Action == NotifyCollectionChangedAction.Reset) { if (SupportsIndex) { if (MultipleSelection) { CurrentSelectionCollection.UpdateIndicesSources(); } if (CurrentSelectedIndex != -1) { var source = GetSource(CurrentSelectedIndex); Sync(source != null ? CurrentSelection.WithSource(source) : CurrentSelection.WithIndex(-1)); } } } else { if (e.NewItems != null) { foreach (var source in e.NewItems) { if (IsSourceSelected(source)) { SelectSourceSafe(source); } } } if (e.OldItems != null) { foreach (var source in e.OldItems) { if (IsSourceInSelection(source)) { UnselectSourceSafe(source); } } } } SyncIndex(false); EnsureSelection(); }
private void SyncIndex(int itemIndex) { if (itemIndex == CurrentSelectedIndex) { return; } if (MultipleSelection) { if (CurrentSelectionCollection.FindByIndex(itemIndex, out var selection)) { if (itemIndex != selection.Index) { CurrentSelectionCollection.UpdateSelection(itemIndex, selection); } } } Sync(CurrentSelection.WithIndex(itemIndex)); }