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.

.NET MAUI Problem with ListView/CollectionView on iOS

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created 9 months ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
softlioncommented, 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.

0reactions
jinxinjuancommented, Aug 16, 2023

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot known issues - .NET MAUI
This article describes some of the known issues with .NET Multi-platform App UI (.NET MAUI), and how you can solve or work around...
Read more >
Critical error when release .Net Maui app in iOS
I'm guessing this issue is related to the list view in iOS and specifically when you try to group the item using
Read more >
Xamarin.Forms ListView/CollectionView data-binding explained!
A question I have seen coming by a lot is: how to trigger a command from ... #databinding #mvvm # maui #xamarinforms #listview...
Read more >
Mobile App Development with .NET MAUI : The Complete ...
NET MAUI : Build Real-World Apps for Android, iOS, and Windows. ... Hierarchical Navigation, Model pages, List View, Collection View, Shell and much...
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