dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.9k stars 1.69k forks source link

ListView + DataTemplateSelector + HasUnevenRows issue on iOS #20261

Open jpiechowiak opened 6 months ago

jpiechowiak commented 6 months ago

Description

When you use DataTemplateSelector with HasUnevenRows you may occur error Specified cast is invalid on iOS.

I've found easy scenario to reproduce (see attached repository). You have to have at least two Data templates and at least one of them should have Label directly under ViewCell. In such case when you alter ItemsSource from second DataTemplate to this one, error will crash your application.

Steps to Reproduce

  1. Run project on iOS from attached reproduction repository
  2. Tap button couple times until you change from data template with image to data template with only label

Link to public reproduction project repository

https://github.com/jpiechowiak/maui-dts-unevenrows-issue

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

-

Did you find any workaround?

In ViewCell which contains only label, wrap Label with container - for instance in StackLayout

Relevant log output

No response

XamlTest commented 4 months ago

Verified this on VS 17.10.0 Preview 1.0(8.0.6). Repro on iOS 17.2 and MacCatalyst, not repro on Windows 11 and Android 14.0-API34 with below Project: maui-dts-unevenrows-issue.zip

iOS Exception:

Screenshot 2024-03-11 at 5 59 34 PM