question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] iOS: CollectionView items don't change their size when item content size is changed

See original GitHub issue

Description

CollectionView items don’t change their size when item content size is changed

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp.MainPage" BackgroundColor="White">

     <StackLayout>
        <Button Text="Button" Clicked="Button_Clicked"/>
        <CollectionView ItemsSource="{Binding Items}" >
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Label Text="{Binding Name}"/>
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
        </CollectionView>
    </StackLayout>
</ContentPage>
public partial class MainPage : ContentPage {
	public MainPage() {
		InitializeComponent();
                BindingContext = this;
	}

        ObservableCollection<SomeItem> _items;
        public ObservableCollection<SomeItem> Items {
            get {
                if (_items == null) {
                    _items = new ObservableCollection<SomeItem>(Enumerable.Range(0, 5).Select(c => {
                        return new SomeItem() { Name = string.Format("Item {0}", c) };
                    }));
                }

                return _items;
            }
        }

        void Button_Clicked(System.Object sender, System.EventArgs e) {
            foreach (SomeItem item in Items) {
                item.Name = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
            }
        }

public class SomeItem : INotifyPropertyChanged {
        string name;
        public string Name {
            get => name;
            set {
                name = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Name)));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}

Expected Behavior

All items change their height

https://user-images.githubusercontent.com/41049348/144585428-ded1d957-bef0-4caf-bf99-9029ccc7624a.mov

Actual Behavior

All items don’t change their height

https://user-images.githubusercontent.com/41049348/144585558-f9c8ed20-166e-46e3-ab46-aa6c01d3d720.mov

Steps to Reproduce

  1. Create a MAUI app
  2. Put Button and CollectionView into StackLayout on the MainPage.xaml
  3. Set ItemTemplate for CollectionView, put into ItemTemplate Grid with Label
  4. In the Button.Clicked event handler change Label.Text
  5. Deploy to iOS simulator and click the Button

Version with bug

Preview 10 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15

Did you find any workaround?

No response

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
AntonKosenkoDXcommented, May 5, 2022

Hello, we are developing DevExpress .NET MAUI controls and experienced the same issue in our CollectionView. This issue has a High priority for us and we have/do not have a workaround. Thank you for your help.

0reactions
AdamBebkocommented, Dec 23, 2022

I am facing this issue as well. ListView updates properly but CollectionView does not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cell size not updating after changing flow layout's itemSize
In my app, I have a full-screen paging collection view and each cell needs to be full-screen as well, so the collection view...
Read more >
issue with collection view sizing | Apple Developer Forums
Looks like it is setting the cell size to layout.estimatedItemSize and not resizing to fit prior to drawing (these are autosized, with full...
Read more >
CollectionView layout issues with nested ...
I've had this problem with CollectionView since the release of MAUI where items are not sized properly on first display.
Read more >
Collection View Cells Self-Sizing: Step by Step Tutorial
In this article you will learn how collection view cells can dynamically adjust their size based on their content.
Read more >
UICollectionViewCell Width and Height programmatically + ...
If you are trying to implement a CollectionView and while using autolayout, collectionview cells won't change the size.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found