/// <summary> /// Constructructor. Takes an optional isMultithreaded argument where when true allows you to update the collection /// from multiple threads. In testing there didn't seem to be any performance hit from turning this on, so I made /// it the default. /// </summary> /// <param name="isThreadSafe"></param> public ConcurrentObservableCollection(bool isMultithreaded) : base(isMultithreaded, ImmutableList <T> .Empty) { _editableCollectionView = EditableImmutableListBridge <T> .Empty(this); PropertyChanged += (s, e) => { if (e.PropertyName == nameof(CollectionView)) { RaisePropertyChanged(nameof(EditableCollectionView)); } }; }
/// <summary> /// Clears flag for indicating an item is being edited, this should be called from the GUI thread, /// and called from the CurrentCellChanged event, as the CellEditEnding event gets fired before the /// edit is committed and will be lost when the underlying collection gets refreshed. /// /// This would normally be called from a WPF DataGrid CurrentCellChanged event. /// </summary> public void EndedEditingItem() { // Check the FreezeUpdates flag is set, else we are not in the middle of an edit. if (_editableCollectionView.FreezeUpdates) { // Clear flag _editableCollectionView.FreezeUpdates = false; // Assign new value to CollectionView so it is recognised as different to existing value _editableCollectionView = _editableCollectionView.UpdateSource((ImmutableList <T>)_internalCollection); // Raise event to display updated collection RaisePropertyChanged(nameof(EditableCollectionView)); } }
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs changes) { // Assign new value to CollectionView so it is recognised as different to existing value _editableCollectionView = _editableCollectionView.UpdateSource((ImmutableList <T>)_internalCollection); base.OnCollectionChanged(changes); }