dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22k stars 1.72k forks source link

ObservableCollection is not returning values for ContentPage (IOS) Bindable Context #13026

Open sstahurski opened 1 year ago

sstahurski commented 1 year ago

Description

I have a content page with a bindable context, a view model with an observable collection. I've tried different types of views ( Listview, scrollable stackview,etc) and the ObservableCollection does not return the values in to the views for the views and subviews at times.

This occurs when scrolling and when the user selects the home button on ios, and then brings the app back to the foreground. The first image is when the app initially comes up, the second is when the app is placed in the background ( home button) and then is brought to the foreground. I have also seen this occur when just scrolling the list.

1 2
Simulator Screen Shot - iPhone 14 - 2023-01-31 at 11 00 09 Simulator Screen Shot - iPhone 14 - 2023-01-31 at 11 00 18

Steps to Reproduce

  1. create an app with a listview and bindable context
  2. put app in back ground
  3. bring app into forground

ALT

  1. scroll the List view.

Link to public reproduction project repository

https://github.com/sstahurski/testListView

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

ios 16.2

Did you find any workaround?

no workaround.

Relevant log output

No response

FBonini22 commented 1 year ago

I am also having this issue, and I have found that others have been experiencing this problem with ListViews since last year. I am trying to come up with a workaround. I tried changing the Caching Strategy, calling InvalidateMeasure on the ListView, and adding items with delays in between adds. foreach(var item in MyCollection) { MyObservableCollection.Add(item); Task.Delay(100); }

None of the above worked, and even when the caching strategy was set to RetainElement, and there was a significant delay between item adds, I could watch the app add completely blank items to the ListView.

ghost commented 1 year ago

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.

FBonini22 commented 1 year ago

Just thought I'd follow up with how I overcame this for anyone looking at this in the future. I ditched the ListView and made my own equivalent. It works fine for now, but I get some .Dispose() warnings in the console.

XAML: <ScrollView VerticalOptions="FillAndExpand"> <StackLayout x:Name="ItemsLayout" VerticalOptions="FillAndExpand"> </StackLayout> </ScrollView>

C#:

private void ClearAndFillItemsList()
    {

        ItemsLayout.Children.Clear();

        foreach(var item in viewModel.Items)
        {
            AddItemToLayout(item);
        }
    }

    private void AddItemToLayout(ItemType item)
    {
        ItemsLayout.Children.Add(new CustomViewDataType(item));
    }

I call ClearAndFillItemsList() in a Refresh method.

The items I'm adding to ItemsLayout have their own DataType inheriting from ContentView. I have my gesture handlers in that code and XAML to handle when items are tapped.

Hope this helps out.

DesmondMilez commented 1 year ago

Just thought I'd follow up with how I overcame this for anyone looking at this in the future. I ditched the ListView and made my own equivalent. It works fine for now, but I get some .Dispose() warnings in the console.

XAML: <ScrollView VerticalOptions="FillAndExpand"> <StackLayout x:Name="ItemsLayout" VerticalOptions="FillAndExpand"> </StackLayout> </ScrollView>

C#:

private void ClearAndFillItemsList()
    {

        ItemsLayout.Children.Clear();

        foreach(var item in viewModel.Items)
        {
            AddItemToLayout(item);
        }
    }

    private void AddItemToLayout(ItemType item)
    {
        ItemsLayout.Children.Add(new CustomViewDataType(item));
    }

I call ClearAndFillItemsList() in a Refresh method.

The items I'm adding to ItemsLayout have their own DataType inheriting from ContentView. I have my gesture handlers in that code and XAML to handle when items are tapped.

Hope this helps out.

Hey, can you publish the repo of the workaround? I am strugling with this too, it happens on MacOS app.

homeyf commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Can repro on iOS platform with sample project. testListView