Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Binding updating issue with ListView?

$
0
0

Hello again!

I need to be very quick, so sorry if this has been answered or the lack of code.

I did a ListView, and set the ItemSource with a Binding to a list on the view model (groupedList). Ok, fine, it works perfectly, with grouping, etc.
I added to the ViewCell a converter to set the background color according to a boolean variable I create called "IsSelected".
Ok, it's still working, and I can get the "selected" items from the list.

The problem came when I used the "updating" command on my ViewModel

        List<MyModel> tempList = await WebApiData.GetList();

        if (tempList != null)
        {
            allList = new ObservableCollection<MyModel>(tempList);
            groupedList = new ObservableCollection<GroupList>(GroupModels(tempList));
        }
        else
        {
            if (allList != null)
                allList.Clear();
            if (groupedList != null)
                groupedList.Clear();
        }

If I had selected some elements, and refresh the page, in the ViewModel, both lists (allList and groupedList) are updated correctly with no elements selected. But the ListView is showing the previous elements selected, and no change made in the View is taking effect in the ViewModel.

I figured out that the ViewModel is not refreshing the list, and is still using the old one, so I have both (old and new) in memory: one in the ViewModel, and the other in the ViewList.
To check it, I moved the clear sentences before the IF clause, to delete the old lists before adding the new ones. And it worked perfectly. It's like Binding or ListView didn't noticed about the change of list, unless the old list get modified or deleted.

Am I right? Did I miss something? Is because I'm using Xamarin 4.10.0.448?

Thank you!


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>