Bug 57674 - XF.UWP ListView not honoring INotifyCollectionChanged
Summary: XF.UWP ListView not honoring INotifyCollectionChanged
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-06-21 19:21 UTC by Alvaro Rivoir
Modified: 2017-12-22 00:31 UTC (History)
4 users (show)

Tags: ac uwp listview itemssource fr
Is this bug a regression?: ---
Last known good build:


Attachments
Solution which reproduces the bug (320.70 KB, application/x-zip-compressed)
2017-06-21 19:21 UTC, Alvaro Rivoir
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Alvaro Rivoir 2017-06-21 19:21:13 UTC
Created attachment 23045 [details]
Solution which reproduces the bug

ListView is not honoring INotifyCollectionChanged in UWP. It works in Android and iOS, but not in UWP.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:XF.INCC"
             x:Class="XF.INCC.MainPage">
    <StackLayout>
        <Button Text="Add" Clicked="OnAddClicked"/>
        <ListView x:Name="listView" VerticalOptions="FillAndExpand"/>
    </StackLayout>
</ContentPage>

    public partial class MainPage : ContentPage
    {
        MyCollection _mycollection = new MyCollection();
        public MainPage()
        {
            InitializeComponent();

            listView.ItemsSource = _mycollection;
        }

        private void OnAddClicked(object sender, EventArgs e)
        {
            _mycollection.AddNewItem();
        }
    }

    internal class MyCollection : IEnumerable<string>, INotifyCollectionChanged
    {
        private List<string> _internalList = new List<string>();
        public MyCollection()
        {
        }


        public IEnumerable<string> GetItems()
        {
            foreach (var item in _internalList)
            {
                yield return item;
            }
        }

        public IEnumerator<string> GetEnumerator()
        {
            return GetItems().GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        internal void AddNewItem()
        {
            var index = _internalList.Count;
            var item = Guid.NewGuid().ToString();
            _internalList.Add(item);
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
        }

        public event NotifyCollectionChangedEventHandler CollectionChanged;

        protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            CollectionChanged?.Invoke(this, e);
        }
    }
Comment 1 Jimmy [MSFT] 2017-06-23 21:56:55 UTC
I am able to reproduce this issue with the project provided. As mentioned, this is only affecting UWP. This bug may be related to bug 37700. I am confirming this report so we can investigate further.

### Version Tests
2.3.6.113   BAD
2.3.5-pre5  BAD
2.3.4.247   BAD
Comment 2 Rui Marinho 2017-12-21 23:17:07 UTC
Should be fixed on 2.6.0-pre1
Comment 3 Samantha Houts [MSFT] 2017-12-22 00:31:11 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1235