Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET MAUI Problem with ListView/CollectionView on iOS #12071

Closed
vsfeedback opened this issue Dec 13, 2022 · 8 comments
Closed

.NET MAUI Problem with ListView/CollectionView on iOS #12071

vsfeedback opened this issue Dec 13, 2022 · 8 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView area-controls-listview ListView and TableView platform/iOS 🍎 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working

Comments

@vsfeedback
Copy link

vsfeedback commented Dec 13, 2022

This issue has been moved from a ticket on Developer Community.


[severity:I'm unable to use this version]
I have a program on the MAUI platform with the MVVM pattern. The problem occurs when running on an Iphone (any) of my program with ListView/CollectionView. When I click on the button or try to just fill in the ListView/Collection view, the program just freezes and nothing happens! I can't write a program for iOS! (There is no difference between Release and Debug)

Example:

C#

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;

namespace MauiApp1;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
        BindingContext = new MainPageModel();
    }
}

public class MainPageModel : INotifyPropertyChanged
{

    public event PropertyChangedEventHandler? PropertyChanged;

    public ICommand ButtonCommand => new Command(UpdateList);

    private void UpdateList()
    {
        List list = new();
        for (int i = 0; i < 20; i++)
        {
            list.Add(new MainPageModel()
            {
                Example = "Text",
                Test = "Test"

            });
        }
        MyItems = new ObservableCollection(list);

    }

    public ObservableCollection MyItems
    {
        get => _MyItems;
        set
        {
            _MyItems = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MyItems)));
        }
    }
    private ObservableCollection _MyItems = new ObservableCollection();

    public string Example
    {
        get => _example;
        set
        {
            _example = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Example)));
        }
    }
    private string _example;

    public string Test
    {
        get => _test;
        set
        {
            _test = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Test)));
        }
    }
    private string _test;
}

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="MauiApp1.MainPage"
             xmlns:local="clr-namespace:MauiApp1"
             x:DataType="local:MainPageModel">
    <ScrollView Padding="6">
        <VerticalStackLayout>
            <Button Text="Add 20 items" Command="{Binding ButtonCommand}" />
            <ListView ItemsSource="{Binding MyItems}" HasUnevenRows="True">
                <ListView.ItemTemplate>
                    <DataTemplate x:DataType="local:MainPageModel">
                        <ViewCell>
                            <Grid>
                                <VerticalStackLayout>
                                    <VerticalStackLayout Margin="0,12,0,0">
                                        <Label Text="{Binding Example}"  />
                                        <Label Text="{Binding Example}"  />
                                        <Label Text="{Binding Example}"  />
                                        <Label Text="{Binding Example}"  />
                                    </VerticalStackLayout>
                                    <VerticalStackLayout Margin="0,12,0,0">
                                        <Label Text="{Binding Test}"  />
                                        <Label Text="{Binding Test}"  />
                                        <Label Text="{Binding Test}"  />
                                        <Label Text="{Binding Test}"  />
                                    </VerticalStackLayout>
                                </VerticalStackLayout>
                            </Grid>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>

PS: I work on Windows 11 - Visual Studio and connect to a MacBook Pro - using the simulator to launch an Iphone


Original Comments

Feedback Bot on 12/4/2022, 04:37 PM:

(private comment, text removed)


Original Solutions

(no solutions)

@Odaronil
Copy link

you copied my XAML code incorrectly from the Developer Community. Please correct it.

@jsuarezruiz jsuarezruiz added platform/iOS 🍎 area-controls-collectionview CollectionView, CarouselView, IndicatorView area-controls-listview ListView and TableView labels Dec 14, 2022
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Dec 14, 2022
@ghost
Copy link

ghost commented Dec 14, 2022

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.

@jsuarezruiz
Copy link
Contributor

you copied my XAML code incorrectly from the Developer Community. Please correct it.

Fixed, thanks for let us know.

@softlion
Copy link
Contributor

You can't embed a ListView/CollectionView/ScrollView inside a VerticalStackLayout, as a VerticalStackLayout has the height of its content, and a ListView/CollectionView/ScrollView has no height except if you set one through HeightRequest.

So nothing will appear in your example, as the height of your ListView is 0.

Not that the height of a ListView/CollectionView/ScrollView is NOT the height of it's content !

@Odaronil
Copy link

Odaronil commented May 3, 2023

You can't embed a ListView/CollectionView/ScrollView inside a VerticalStackLayout, as a VerticalStackLayout has the height of its content, and a ListView/CollectionView/ScrollView has no height except if you set one through HeightRequest.

So nothing will appear in your example, as the height of your ListView is 0.

Not that the height of a ListView/CollectionView/ScrollView is NOT the height of it's content !

softlion,
If set manually, it works, but it should also work automatically (as in Android). But that's not the only problem. There is a problem with both performance and content display, etc. I think if you made the app with CollectrionView, then you know what I mean. Here Microsoft clearly needs to work on the levels of collectionView for both Android and iOS. Since it is very difficult to make any application without ListView/CollectionView...

@softlion
Copy link
Contributor

softlion commented May 3, 2023

I don't have any performance issue after embedding CollectionView inside ContentView. It can scroll 10k items very fast.

But I agree that it requires a couple of trick that should be out of the box for everyone.

@samhouts samhouts added the t/bug Something isn't working label Jul 31, 2023
@jinxinjuan jinxinjuan added s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Aug 16, 2023
@ghost
Copy link

ghost commented Aug 16, 2023

Hi @vsfeedback. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@jinxinjuan
Copy link

Verified this issue with Visual Studio Enterprise 17.8.0 Preview 1.0(.NET8). Not repro on iOS platforms with sample project (ListViewDemos). maui-samples/7.0/UserInterface/Views/ListViewDemos at main · dotnet/maui-samples (github.com)

@samhouts samhouts modified the milestones: Backlog, .NET 8 + Servicing Aug 17, 2023
@ghost ghost closed this as completed Aug 25, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 24, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView area-controls-listview ListView and TableView platform/iOS 🍎 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants