xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

[Bug] CollectionView Items are reversed on AddRange #10826

Open YZahringer opened 4 years ago

YZahringer commented 4 years ago

Description

Using the AddRange method to optimize the insert of elements in an ObservableCollection binded to CollectionView adds them in reverse order.

I've tried with two different implementations of Range ObservableCollection, same issue:

Expected Behavior

Items are added in order with AddRange.

Actual Behavior

Items are added and removed in reverse order.

Basic Information

Screenshots

With multiple Add on ObservableCollection

2zP8mzuwKk

With AddRange on ObservableCollection

HR3C7AUvav (items are added in reverse order and remove it in reverse order as well)

Reproduction Link

CollectionView AddRange sample

jsuarezruiz commented 4 years ago

@YZahringer Thanks for the reproduction sample. I have done several tests and can reproduce the issue using 4.6 and 4.7-pre2.

Captura de pantalla 2020-06-02 a las 13 55 36

Then, I have created a tests in Xamarin.Forms Core Gallery using the MvvmHelpers ObservableRangeCollection code and, cannot reproduce the issue: https://gist.github.com/jsuarezruiz/bbed609b8382a72c6304c4244f48b964

Captura de pantalla 2020-06-02 a las 13 56 16

I will check if it has been fixed by another issue fix, etc.

YZahringer commented 4 years ago

@jsuarezruiz Thank you for the answer. In the test there is no ItemTemplate defined, perhaps without it does not reproduce the problem?

jsuarezruiz commented 4 years ago

You are right. Using strings I didn't notice the ItemTemplate in your example. So, using ItemTemplate, can reproduce in Core Gallery too.

MSiccDev commented 4 years ago

Any news on this? We’re using ObservableRangeCollection for a reason...

banjahman commented 4 years ago

any plans on when this will get fixed? This is a pretty critical blocker for me at the moment.

YZahringer commented 4 years ago

Repro project updated to XF 4.8.0.1269 (issue persist)

YZahringer commented 3 years ago

Repro project updated to XF 5.0.0.1829-pre6 (issue persist).

I also added and tried with new XCT ObservableRangeCollection, same problem.

amaneshi commented 3 years ago

Also interested in this issue progress. Use latest XF 5.0.0.2012 and reverse still there (actually on refresh, initial AddRange work normal). I also use XCT ObservableRangeCollection.

Update: But when I changed collection update from

MyCollection.Clear()
MyCollection.AddRange(NewCollection)

to

MyCollection.ReplaceRange(NewCollection)

this issue disappeared. In case somebody look for workaround...

YZahringer commented 2 years ago

.NET MAUI related issue #6471