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.

MeasureFirstItem makes items disappear on Android

See original GitHub issue

Description

I have a CollectionView where ItemSizingStrategy is set to MeasureFirstItem. The properties of the times are changed some time of the CollectionView is loaded. Somehow, this makes some items become invisible on Android. It works fine on Windows.

Originally, my list looks like this:

image

Then, the two first items should be changed to green. But the second one just disappears:

image

In Windows it’s works fine:

image

It’s very strange 😃

Steps to Reproduce

  1. Create a new Maui app.
  2. Change MainPage.xaml to:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:v="clr-namespace:MauiIssues"
             x:Class="MauiIssues.MainPage"
             >
    <Grid>
        <CollectionView ItemsSource="{Binding Issues}" ItemSizingStrategy="MeasureFirstItem">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Label Text="{Binding Title, Mode=OneWay}"
                            TextColor="Red"
                            IsVisible="{Binding IsRed}"
                                />

                        <Label Text="{Binding Title, Mode=OneWay}"
                            TextColor="Green"
                            IsVisible="{Binding IsGreen}}"
                                />
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </Grid>
</ContentPage>
  1. Change MainPage.cs to:
using System.Collections.ObjectModel;

namespace MauiIssues;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();

        BindingContext = this;
    }

    public class Issue : BindableObject
    {
        public string Title { get; set; }
        public bool IsRed { get; set; } = true;
        public bool IsGreen => !IsRed;

        public void MakeGreen()
        {
            IsRed = false;
            OnPropertyChanged(nameof(IsGreen));
            OnPropertyChanged(nameof(IsRed));
        }
    }

    public ObservableCollection<Issue> Issues { get; } = new ObservableCollection<Issue>();

    protected async override void OnAppearing()
    {
        base.OnAppearing();

        Issues.Add(new Issue { Title = "Issue 1" });
        Issues.Add(new Issue { Title = "Issue 2" });
        Issues.Add(new Issue { Title = "Issue 3" });

        await Task.Delay(4000);

        Issues[0].MakeGreen();
        Issues[1].MakeGreen();
    }
}

Run the project in Android.

Full sample code: https://github.com/pekspro/MauiIssues/tree/7562_MeasureFirstItem_makes_items_disappear

Version with bug

6.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Windows 10.0.17763.0, Android 11

Did you find any workaround?

Removing ItemSizingStrategy="MeasureFirstItem" solves the problem.

Relevant log output

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:11

github_iconTop GitHub Comments

6reactions
peksprocommented, Nov 11, 2022

I’ve updated sample application to .NET 7. The same issue remains. I have also tried the work around from @ToolmakerSteve, but it didn’t helped.

5reactions
jvakoscommented, Jul 19, 2023

Bug remains in dotnet 8.0.0-preview.6.8686.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MeasureFirstItem makes items disappear on Android
MeasureFirstItem makes items disappear on Android #8202. Sign in to view logs · Sign in to view logs. Summary. MeasureFirstItem makes items disappear...
Read more >
Recycler view item disappearing - android
This will solve your issue. Now, clicking on each item, makes change on all items in the list. Share.
Read more >
Xamarin.Forms 4.3.0.991250 (4.3.0 Service Release 4) ...
Release notes detailing new features, improvements, and issues fixed in Xamarin.Forms 4.3.0.991250 (4.3.0 Service Release 4)
Read more >
Items keep disappearing when an unit is sold.
Is anyone experiencing items disappearing when an unit is sold holding multiple items? Just yesterday, I had a Freljord emblem disappear ...
Read more >
[ATM8] Storage items disappearing : r/allthemods
I found a weird bug that just makes item disappear. it happend to me so far with a dank 4 (with all my...
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