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

Binding CollectionView/CarouselView to lists of primitive types doesn't work on Release Builds #16021

Closed
stefanpirkl opened this issue Jul 6, 2023 · 3 comments · Fixed by #22056
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView fixed-in-8.0.80 fixed-in-9.0.0-preview.7.24407.4 linker issues with objects being trimmed inappropriately (sub: perf) 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

@stefanpirkl
Copy link

Description

A CollectionView/CarouselView bound to an IList with primitive types doesn't render items on release builds.

Tested on Windows and Android, both don't work.

Debug:
image

Release:
image

Steps to Reproduce

  1. Create a new .NET MAUI project

  2. Add a view model with a list property of type List and some elements:
    ` internal class MainPageViewModel : BindableObject
    {
    private IList _items = new List { "first value", "second value", "third value" };

     public IList<string> Items
     {
         get { return _items; }
         set { _items = value; OnPropertyChanged(nameof(Items)); }
     }
    

    }`

  3. Bind the view model to MainPage.xaml.cs:
    ` public partial class MainPage : ContentPage
    {
    MainPageViewModel viewModel = new MainPageViewModel();

     public MainPage()
     {
         InitializeComponent();
    
         BindingContext = viewModel;
     }
    

    }`

  4. Add a CollectionView to MainPage.xaml, bound to the list in MainPageViewModel:
    <CollectionView ItemsSource="{Binding Items}"> <CollectionView.ItemTemplate> <DataTemplate> <Label Text="{Binding}" /> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView>

  5. Do a release build, observe that nothing is rendered.

Link to public reproduction project repository

https://github.com/stefanpirkl/bugreport-maui-collectionview-primitive-list-on-release

Version with bug

8.0.0-preview.5.8529

Last version that worked well

Unknown/Other

Affected platforms

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

Affected platform versions

Windows 10, Android 9 and up

Did you find any workaround?

Changing the List to a custom model class with a single string property in it.

Relevant log output

No response

@stefanpirkl stefanpirkl added the t/bug Something isn't working label Jul 6, 2023
@Eilon Eilon added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Jul 6, 2023
@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Aug 2, 2023
@XamlTest
Copy link

XamlTest commented Aug 2, 2023

Verified this on Visual Studio Enterprise 17.7.0 Preview 6.0. Repro on Windows 11 and Android 13.0-API33 .NET 8 with below Project:
CollectionViewBinding.zip

@samhouts samhouts added the linker issues with objects being trimmed inappropriately (sub: perf) label Aug 3, 2023
@IsmailHassani
Copy link

IsmailHassani commented Mar 2, 2024

I've encountered the same issue with Release build.
It has to do with the issue #20002 that states you have to specify the x:DataType to fix the binding.
For strings i use:
<DataTemplate x:DataType="x:String">

@stefanpirkl
Copy link
Author

I've encountered the same issue with Release build. It has to do with the issue #20002 that states you have to specify the x:DataType to fix the binding. For strings i use: <DataTemplate x:DataType="x:String">

Wow, thank you! This did really fix it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView fixed-in-8.0.80 fixed-in-9.0.0-preview.7.24407.4 linker issues with objects being trimmed inappropriately (sub: perf) 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

Successfully merging a pull request may close this issue.

6 participants