2
votes

I can't seem to be able to change the ItemsSource in LongListSelector. After doing some research, it appears that LongListSelector ignores any changes in ItemsSource. Am I correct?g If yes, is there a workaround?

This what I'm trying to do. I have an option to sort the City list either by country or cities. Something like this:

var groupByCountry = from City in App.ViewModelCity.Items
                                group city by city.GroupByCountry into c
                                orderby c.Key
                                select new Group<Currency>(c.Key, c);

var groupByCity = from City in App.ViewModelCity.Items
                                group city by city.GroupByCity into c
                                orderby c.Key
                                select new Group<City>(c.Key, c);

SO basically both are the same, just the grouping is different. My idea was to simple change the ItemsSource to either groupByCountry or groupByCity, depending on the user choice. Unfortunately, changing the ItemsSource has no effect. It simply won't update. Only when the app is restarted (with the preferred source stored) the LongListSelector is updated.

So is there a way to force LongListSelector to update the ItemsSource? If not, what would be a good workaround?

1
Try writing it as (from City in...).ToList(); Maybe deferred execution is the problem here. - Toni Petrina
This related answer seems to be the work around - Neil Turner

1 Answers

0
votes

I develop in WP7, I set the ItemSource to null before the real assignment so that UI will update for new ItemSource.

LongListSelectorA.ItemsSource = null;
Binding b;
b = new Binding("CollectionInViewModel");
LongListSelectorA.SetBinding(LongListSelector.ItemsSourceProperty, b);

Give it a shot, wish you luck. :)