maui icon indicating copy to clipboard operation
maui copied to clipboard

ListView ViewCell content disappears when the application enters the foreground

Open ultra133 opened this issue 2 years ago • 1 comments

Description

A simple page consists only a ListView, which has a ViewCell as DataTemplate.

When the app on iOS (whether device or simulator) goes to the background and then back to the foreground, the content of the CellViews disappears. Only empty cells remain.

Steps to Reproduce

  1. Create a New .NET MAUI App from the template
  2. Replace the content of MainPage.xaml
<?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"
             x:Class="ListTest.MainPage">

    <ContentPage.ToolbarItems>

    </ContentPage.ToolbarItems>

    <ListView>

        <ListView.ItemsSource>
            <x:Array Type="{x:Type x:String}">
                <x:String>One</x:String>
                <x:String>Two</x:String>
                <x:String>Three</x:String>
            </x:Array>
        </ListView.ItemsSource>

        <ListView.ItemTemplate>
            <DataTemplate x:DataType="x:String">
                <ViewCell>
                    <Grid
                        ColumnDefinitions="80,*">
                        <Button Text="{Binding .}"/>
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>

    </ListView>

</ContentPage>
  1. Run the app on iOS Simulator 16.0. The app shows a list with three lines of buttons.
  2. Send the app to the background. Do not close the app!
  3. Pull the app back to the foreground

What should happen:

The app looks like before.

What happens instead:

The three lines are still visible, but the buttons disappear.

Link to public reproduction project repository

https://none

Version with bug

7.0 (current)

Last version that worked well

This worked with Xamarin! So it's a big issue when migrating to .NET MAUI.

Affected platforms

iOS

Affected platform versions

iOS 16

Did you find any workaround?

No

Relevant log output

No response

ultra133 avatar Nov 24 '22 21:11 ultra133

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Nov 29 '22 19:11 ghost

This is almost CERTAINLY linked to my issue https://github.com/dotnet/maui/issues/11598

I don't see how this isn't getting some serious, and prioritised, attention.

Can't use ListView in app without random failures is a MASSIVE blocker for my app that is otherwise ready to be released to our user base.

net 7.0 is 'production ready' apparently so this should be getting dealt with at way higher priority than 'backlog' @rachelkang ???

petermauger avatar Nov 30 '22 01:11 petermauger

@jsuarezruiz @rachelkang If someone can help me get a VS project setup so I can actually breakpoint and debug the MAUI code behind this then I'll put together and submit a PR for it myself. I can't seem to put together a MAUI app project that uses the repository projects instead of the packaged frameworks?

petermauger avatar Nov 30 '22 01:11 petermauger

We must conclude that migrating existing Xamarin apps to MAUI is not practical at this time, and will not be in the foreseeable future. New projects will have to abandon the use of ListView and use CollectionView instead.

@petermauger Contribution is always welcome. You may follow the documentation. If you have questions regarding contribution, you may open a discussion.

ultra133 avatar Nov 30 '22 08:11 ultra133

Verified this is still an issue at this time, I've only been able to reproduce this on iOS. I've also had issue with scrolling as well, where listview items as well in larger lists disappear ( i.e they are there but the contents are not displayed.)

sstahurski avatar Jan 31 '23 16:01 sstahurski

Still having the same issue as well, only on iOS.

FBonini22 avatar Feb 01 '23 22:02 FBonini22

March 1st, still having this issue on iOS.

knprice avatar Mar 02 '23 01:03 knprice

There is this https://github.com/dotnet/maui/pull/13669

matmork avatar Mar 03 '23 19:03 matmork

March, 28. Is there any chance that ListView will be possible to use in the near future?

kgaripova avatar Mar 28 '23 17:03 kgaripova

To the MAUI team, I am sorry but this is not a "move to backlog" issue. This is critical. I was shocked to see this issue was created back in November with no response since.

  1. DIsplaying lists is a very common app function.
  2. Sending apps to the background is a very common user action.

One might recommend that we could use CollectionView, but frankly, that also has a whole separate set of issues that made me switch back to ListView.

nicjay avatar Apr 07 '23 23:04 nicjay

Those experiencing this issue, is x:Array and x:String always involved?

  • https://github.com/dotnet/maui/pull/14546

If you have an example that hit this problem, and are not using these, let me know.

I will test, but I think #14546 likely fixes it.

jonathanpeppers avatar Apr 19 '23 16:04 jonathanpeppers

Jonathan, this problem here is not related to your x:Array patch. The problem described here also occurs in debug mode and independently of the items source. The x:Array was used for demonstration purposes only.

ultra133 avatar Apr 20 '23 05:04 ultra133

Verified this on Visual Studio Enterprise 17.7.0 Preview 1.0. Repro on iOS 16.4 with above provided Project: ListTest.zip

Pull the app back to the foreground, the buttons disappear. image

XamlTest avatar Jun 08 '23 06:06 XamlTest

TableView use ViewCell have the same problem, IOS and more than 2 viewcells will raise this problem, android is ok.

xufeitt avatar Jun 08 '23 13:06 xufeitt

This is also an issue on my side as well on latest VS2022 17.6.2. The only workaround I found is to use ListViewCachingStrategy.RecycleElement but this mode is very slow so its not that good of an option when having ListView with moderate to large number of items.

TamerIrdais avatar Jun 11 '23 10:06 TamerIrdais

I have the similar issue on MacCatalyst when scrolling listview, viewcell content disappears. dotnet version 7.0.302.

RogueJin avatar Jun 12 '23 12:06 RogueJin

Just started with template MAUI to port my XF apps. Tried one page to convert to maui. A settings page with a tableview with 10 view cells. Same issue. When navigating away from my app and back, most of the cells are gone, empty cells are left!

mnidhk avatar Jun 12 '23 16:06 mnidhk

As a work-around, I am using a CollectionView instead of a ListView. The problem appears to be with the ViewCell in the DataTemplate within a ListView.ItemTemplate. CollectionView ItemTemplates do not use ViewCell.

peterbersani avatar Jun 14 '23 18:06 peterbersani

I was struggling with this issue and CachingStrategy="RecycleElement" fixed it on the XAML of the list view

TiernanDeFranco avatar Jun 20 '23 16:06 TiernanDeFranco

Thanks @TamerIrdais and @HealthMode. This workaround worked for me.

MuhSchaf avatar Jun 28 '23 14:06 MuhSchaf

I see there is #15036 that was merged that might have to do with this. Is there anyone that is already on the .NET 8 preview bits that might confirm if the problem still persists there? This change should be available in .NET 8 preview 5.

jfversluis avatar Jul 04 '23 18:07 jfversluis

@jfversluis, I don't think .NET 8 is yet available on the Visual Studio for Mac preview channel, is it? Even on ARM64 Windows 11 and Visual Studio 17.7.0 Preview 2.0, I may build and run .NET 8 Console apps or ASP.NET projects, but no MAUI projects yet.

ultra133 avatar Jul 05 '23 06:07 ultra133

I was struggling with this issue and CachingStrategy="RecycleElement" fixed it on the XAML of the list view

Thanks, worked for me

chema-code avatar Jul 05 '23 09:07 chema-code

I tested this against .NET8 and it appears fixed

I'm guessing it's fixed by https://github.com/dotnet/maui/pull/15036

PureWeen avatar Jul 26 '23 16:07 PureWeen

Hello guys, i still have this issue.

If i am using Listview with ViewCell and ViewCell MenuItems. When i am deleting item without CachingStrategy="RecycleElement" when another items are blank. When i am deleting item with CachingStrategy="RecycleElement" when the item are not blank but the MenuItem jumps to another Item and is opened without user swipe.

But it is only on IOS, on Android it works fine

I dont wanna use SwipeView instead of ViewCell.MenuteItem because it looks not good :/

Vogel9696 avatar Aug 15 '23 09:08 Vogel9696

Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!

ghost avatar Aug 15 '23 09:08 ghost