MeasureFirstItem makes items disappear on Android
See original GitHub issueDescription
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:
Then, the two first items should be changed to green. But the second one just disappears:
In Windows it’s works fine:
It’s very strange 😃
Steps to Reproduce
- Create a new Maui app.
- 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>
- 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:
- Created a year ago
- Reactions:4
- Comments:11
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Bug remains in dotnet 8.0.0-preview.6.8686.