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

[NET 8, RC1, Windows] wrong initial BindingConext in CollectionView DataTemplate #17515

Closed
malsabi opened this issue Sep 20, 2023 · 1 comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/windows 🪟 t/bug Something isn't working

Comments

@malsabi
Copy link

malsabi commented Sep 20, 2023

Description

The BindingContext for DataTemplates in CollectionView seems to be broken in .NET 8 RC1. Upon loading the CollectionView Items, the template object initially receives BindingContex reference to the BindingContext of the CollectionView parent. Immediately after it receives another BindingContext reference - this time the right reference to the Model of Items. This behavior has big performance impact because it sets Bindings twice and causes BindingFailures during the first cycle.

Note: I can see the data but a run time exception will occur whenever the button command is executed that is bounded to the view model.

Tested on Windows and Windows subsystem for Android - only Windows version seems affected.

Steps to Reproduce

  1. Load the repository and run the app in debug mode.
  2. Observe raising count of BindingFailures with reference to wrong BindingContext. Data are displayed correctly, because it eventually receives the right BindingContext. The behavior is tracked in the Debug output window:

Warnings List:

Microsoft.Maui.Controls.Xaml.Diagnostics.BindingDiagnostics: Warning: 'Title' property not found on 'CollectionViewIssue.MainPageViewModel', target property: 'Microsoft.Maui.Controls.Label.Text'
Microsoft.Maui.Controls.Xaml.Diagnostics.BindingDiagnostics: Warning: 'Program' property not found on 'CollectionViewIssue.MainPageViewModel', target property: 'Microsoft.Maui.Controls.Label.Text'
Microsoft.Maui.Controls.Xaml.Diagnostics.BindingDiagnostics: Warning: 'Course' property not found on 'CollectionViewIssue.MainPageViewModel', target property: 'Microsoft.Maui.Controls.Label.Text'
Microsoft.Maui.Controls.Xaml.Diagnostics.BindingDiagnostics: Warning: 'EndDate' property not found on 'CollectionViewIssue.MainPageViewModel', target property: 'Microsoft.Maui.Controls.Label.Text'

Runtime fatal exception:
Exception = {"Parameter "parameter" (object) cannot be of type CollectionViewIssue.MainPageViewModel, as the command type requires an argument of type CollectionViewIssue.Assessment. (Parameter 'parameter')"}

Note: This 100% works without any issues on Android, its only happening on windows.

Link to public reproduction project repository

https://github.com/malsabi/CollectionViewIssue

Version with bug

8.0.0-rc.1.9171

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.92

Affected platforms

Windows

Affected platform versions

Windows SDK 10.0.19041.0

Did you find any workaround?

All the .NET 7 builds seem working properly, including nightly releases.

Relevant log output

No response

@malsabi malsabi added the t/bug Something isn't working label Sep 20, 2023
@PureWeen
Copy link
Member

This should be fixed by #17348

Thank you for verifying against nightly!!!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 21, 2023
@samhouts samhouts added platform/windows 🪟 area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Feb 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/windows 🪟 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants