Skip to content

Minimal support for ObservableCollection<T> range actions #10845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sergio0694
Copy link

@Sergio0694 Sergio0694 commented May 12, 2025

Fixes #52
Supersedes #9568, #6097

Description

This PR is needed to unblock dotnet/runtime#18087.
To keep work/risk to a minimum, this PR only unblocks WPF by avoiding crashes.
That is, it treats all range operations as collection resets, and nothing else.
This can be further improved later, but it's sufficient to at least unblock upstream .NET work.

Customer Impact

WPF apps with code using any new range APIs (dotnet/runtime#18087) will not crash.

Regression

No.

Testing

I'll need help with this.

Risk

Minimal. Changes are minimal and scoped, and only affect code paths that were previously throwing already.

Microsoft Reviewers: Open in CodeFlow

@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels May 12, 2025
@miloush
Copy link
Contributor

miloush commented May 12, 2025

Looks like a reasonable compromise to me. Did you test it gets you unblocked?

@Sergio0694
Copy link
Author

@miloush I'm not really familiar with the WPF test infrastructure, I was hoping for some guidance/help on that part 😅

@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/observable-range-support branch from 461531a to 9314b53 Compare May 12, 2025 22:00
@michael-hawker
Copy link

@Sergio0694 were you able to run the existing tests as called out in the contribution guide here? https://github.com/dotnet/wpf/blob/main/Documentation/developer-guide.md

It'd be great if someone from the WPF team (or familiar with the codebase) could update the contribution guide to explain how to add new tests, since that's been a requirement for new fixes/features.

Comment on lines +1469 to 1478
private bool IsCollectionChangedRangeAction(NotifyCollectionChangedEventArgs e)
{
return
(e.Action == NotifyCollectionChangedAction.Add && e.NewItems.Count > 1) ||
(e.Action == NotifyCollectionChangedAction.Remove && e.OldItems.Count > 1) ||
(e.Action == NotifyCollectionChangedAction.Replace && (e.OldItems.Count > 1 || e.NewItems.Count > 1)) ||
(e.Action == NotifyCollectionChangedAction.Move && (e.OldItems.Count > 1 || e.NewItems.Count > 1));
}

/// <summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are creating 4x the same method. Cant this be made static and moved into a helper class or something like that instead of duplicating code all over?

Copy link
Member

@h3xds1nz h3xds1nz May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All it needs is private protected on CollectionView as its a base class for all of them, Selector can live with dupl imho.

@h3xds1nz
Copy link
Member

@Sergio0694 I think its best if you get in touch with the team internally, a lot of the tests aren't in this repo, especially the functional ones. There are also CV tests in https://github.com/dotnet/wpf-test but afaik that's not everything.

@michael-hawker
Copy link

Thanks @h3xds1nz for the heads up, we've reached out to them directly too! Just bootstrapping the process here with the PR to lead the conversation in the open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions draft PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improved INotifyCollectionChanged Handling
5 participants