Windows Phone CollectionViewSort not showing anything

不羁的心 提交于 2019-12-06 13:55:20
Johan Falk

The problem is that the LongListSelector control requires that its ItemsSource implements IList, which CollectionViewSource doesn't do. This means you can't bind a CollectionViewSource to a LongListSelector out of the box. You can see this by trying to set it in the code-behind file like this:

myLongListSelector.ItemsSource = myCollectionViewSource.View;

Which gives an error saying it can't convert the view to an IList.

I know atleast two solutions to this, one is to write a wrapper class around CollectionViewSource which does implement IList and then bind to that. Another question gives an example of this (I haven't tried it thought): LongListSelector grouping using CollectionView in Windows Phone 7 or Windows Phone 8

Another method is to not use CollectionViewSource and instead using System.Linq for sorting like suggested in this question: How to Sort a LongListSelector in Windows Phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!