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

DataTemplateSelector on CollectionView is completely broken - templates don't match BindingContext #12988

Closed
Vroomer opened this issue Jan 29, 2023 · 7 comments · Fixed by #20875
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView delighter fixed-in-8.0.10 fixed-in-9.0.0-preview.2.10293 p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint platform/windows 🪟 s/duplicate 2️⃣ This issue or pull request already exists s/triaged Issue has been reviewed t/bug Something isn't working
Milestone

Comments

@Vroomer
Copy link

Vroomer commented Jan 29, 2023

Description

Items in CollectionView utilizing DataTemplateSelector get often assigned to wrong DataTemplate. It appears to be a problem related to recycling views. While first items are usually displayed with correct DataTemplate, once the recycling kicks in the DataTemplates are mismatched. It's a serious issue as it makes the DataTemplateSelector unusable without any workaround. The problem was observed on Windows. Other platforms were not tested.

It might be the same problem as #11272. There is also a related PR to this issue right now #12011, but both the issue and PR mention only Android and iOS and the description of the problem is different. In my case the views get recycled, but incorrectly.

I made a sample showing list of colors to visualize the problem. Each row consists of two colors - one color assigned by DataTemplate and the other assigned by BindingContext.

Screenshot 2023-01-30 000442

Steps to Reproduce

  1. Load the repository and run the app.
  2. Scroll the CollectionView to trigger virtualization.
  3. Notice mismatched colors. Left half is the color assigned by DataTemplate, right half is color from BindingContext. Differences in numbers can help identify recycled views.

Link to public reproduction project repository

https://github.com/Vroomer/MAUI-CollectionView-DataTemplateSelector-Bug.git

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

Windows SDK 10.0.22621

Did you find any workaround?

No response

Relevant log output

No response

@Vroomer Vroomer added the t/bug Something isn't working label Jan 29, 2023
@jsuarezruiz
Copy link
Contributor

Related or the same as #11272

@jsuarezruiz jsuarezruiz added the s/duplicate 2️⃣ This issue or pull request already exists label Jan 30, 2023
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jan 30, 2023
@ghost
Copy link

ghost commented Jan 30, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@ghost
Copy link

ghost commented Jun 13, 2023

Hi @Vroomer. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@homeyf
Copy link

homeyf commented Jun 13, 2023

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Not repro on Windows platform with sample project.
MAUI-CollectionView-DataTemplateSelector-Bug.git

@Vroomer
Copy link
Author

Vroomer commented Jun 15, 2023

image
image
@homeyf which version? I can still reproduce it in main branch 7.0.0-ci.net7.18626

@ghost ghost removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Jun 15, 2023
@Eitsop
Copy link

Eitsop commented Aug 11, 2023

I also have found this an issue (8.2.1) - I have ~130 entries to enumerate, though the DataTemplateSelector only gets called 25 times, then it appears the remaining entries are still mapped to the first 25 and no more calls are made.

@samhouts samhouts added the p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint label Aug 16, 2023
@samhouts samhouts modified the milestones: Backlog, .NET 8 SR2 Oct 5, 2023
@last-Programmer
Copy link

last-Programmer commented Dec 21, 2023

I am also facing this issue. Collectionview control is not usable with this bug if we have to vertically scroll. I am trying to convert the existing xamaring app to maui and stuck with this. cant migrate it without this bug is fixed.

Update:
It seems to be that if the template has control that is data bound then it works. If the controls is built on the fly with the bindingcontext values it does not work. i was able to solve my problem by changing the datatemplate controls to be data bound rather than building with the controls to use values from bindingcontext.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView delighter fixed-in-8.0.10 fixed-in-9.0.0-preview.2.10293 p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint platform/windows 🪟 s/duplicate 2️⃣ This issue or pull request already exists s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants