DynamicData: [Bug]: Unexpected "Reset" Action in CollectionChanged Event When Adding data to ReadOnlyObservableCollection from SourceList

Describe the bug 🐞

When binding a DynamicData.SourceList to a ReadOnlyObservableCollection in a WPF application, and then adding data to the SourceList, the e.Action property in the CollectionChanged event of the ReadOnlyObservableCollection is reported as β€œReset” instead of β€œAdd.” However, when adding a data again to the SourceList, the e.Action property is reported as β€˜Add’.

Code snippet: Properties:

private readonly SourceList<Person> _parentsSource = new SourceList<Person>();
public ReadOnlyObservableCollection<Person> Parents
{
    get;
}

Codes:

_parentsSource.Connect()
    .ObserveOn(RxApp.MainThreadScheduler)
    .Bind(out var parents)
    .Subscribe();

Parents = parents;
(Parents as INotifyCollectionChanged).CollectionChanged += MainWindow_CollectionChanged;

Button click codes:

private void AddADataButton_Click(object sender, RoutedEventArgs e)
{
    var data = new Person() { FirstName = "Data", LastName = "Data"};
    _parentsSource.Add(data);
}

Step to reproduce

  1. Run the sample.
  2. Click the β€œADD” button.
  3. Ensure the Action property value shown in the MessageBox [i.e., β€œReset”].
  4. Again click the β€œADD” button.
  5. Ensure the Action property value shown in the MessageBox [i.e.,β€œAdd”].

Reproduction repository

NA

Expected behavior

The e.Action property in the CollectionChanged event of the ReadOnlyObservableCollection should be reported as β€œAdd” when adding an item to the SourceList.

Screenshots πŸ–ΌοΈ

When adding the data for the first time. image

When adding the data for second time. image

I have attached the sample for the replication.

ReadOnlyObservableCollection_SimpleSample.zip

IDE

Visual Studio 2022

Operating system

Windows

Version

No response

Device

No response

DynamicData Version

8.1.1

Additional information ℹ️

No response

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 17

Most upvoted comments

I’ve introduced changes (not deployed yet) which allows the control of reset operations in dynamic data.

I have introduced code which enables binding to be turned off

 .Bind(out var parents, BindingOptions.NeverFireReset())

and it seems to fix the issue. Annoyingly I have to grab a free trial of Synch Fusion to test!

See description of this https://github.com/reactivemarbles/DynamicData/pull/776 for more details. It will be released soon.

BTW I advise not to turn off reset threshold system wide as it is a seriously important performance optimisier

I think the problem with introducing more libraries is it could explode into way more than we wish to maintain. Whereas keeping it as a single library is comparatively simple.