Skip to content
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

Problem updating CollectionView ItemSource, when the modification is triggered by one of the items in the list #22122

Open
nicop85 opened this issue Apr 29, 2024 · 4 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@nicop85
Copy link

nicop85 commented Apr 29, 2024

Description

Think of a scenario where you have a list of persons and you want yo pin/unpin some of them as your favorites. You will have a CollectionView with it's ItemSource set to an ObservableCollection of persons. Each one of this persons will have a name and a boolean flag to know if they are favorite or not. Then, in the ItemTemplate, each row will display the name of the person and a button to pin/unpin them as favorite.

The idea is that when the user click the button to pin/unpin a person, it will change the status of the isFavorite flag and it should update the list to show all the favorite persons first and then the rest of them. A very common use case scenario of a list with some kind of preference in the items.

The logic behind the scenes, is that when a user clicks the button to pin/unpin a person, it will first change the IsFavorite flag of that person and then execute a method that performs an ObservableCollection.Clear() and then re fill it again with the updated persons.

The problem I've found is that the update in the item flag is performed well, but the Iist itself doesn't get reorder the right way showing the favorite ones first. This seems to only occur when the update was triggered by an item of the list, because if I put a button to refresh the list and execute the same code to re fill the ObservableCollection, everything works as expected.

Am I missing something or did I make any mistake in the code? Or is it a bug in the CollectionView?

I have tested this in all the 8.0.x versions of MAUI and even in some of 7.0.x, so I guess is something that was there for quite a while or perhaps I'm doing something wrong.

Any advice, please let me know

Steps to Reproduce

  1. Clone the repository I'm linking below
  2. Execute the code in desktop or mobile
  3. Try to pin a person different than the first listed one
  4. It should be shown at the top of the list but it will remain in its position
  5. Make the gesture to refresh the list if you are in mobile, or click the refresh button if you are in desktop
  6. The list will then be shown as expected

Link to public reproduction project repository

https://github.com/nicop85/TestCollectionViewRefresh.git

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

Android 11 and up, Windows 10.0.17763.0 and up

Did you find any workaround?

Not yet

Relevant log output

No response

@nicop85 nicop85 added the t/bug Something isn't working label Apr 29, 2024
@kevinxufei kevinxufei added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Apr 30, 2024
@kevinxufei
Copy link
Collaborator

kevinxufei commented Apr 30, 2024

Can repro this issue at android/Windows platforms on the latest 17.10 Preview 5 (8.0.21/8.0.7).

@PureWeen
Copy link
Member

PureWeen commented May 2, 2024

/similarissues

Copy link
Contributor

github-actions bot commented May 2, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@nicop85
Copy link
Author

nicop85 commented May 3, 2024

None of those similar issues seems to be related to this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants