I would like to be able to sort the data bound to my LongListSelector in ascending or descending order. I am having trouble binding sorted data to my LongListSelector. Initially, without trying to implement my solution, my solution worked, but I believe that I have something missing when sorting. I also tried How to sort LongListSelector using CollectionViewSource with no luck. What is the best way to sort LongListSelector?
MainPage.xaml
<phone:LongListSelector x:Name="Recent" Margin="0,0,0,72" LayoutMode="Grid" GridCellSize="108,108" SelectionChanged="recent_SelectionChanged">
MainPage.xaml.cs (OLD)
protected override void OnNavigatedTo(NavigationEventArgs e) { Recent.ItemsSource = App.PictureList.Pictures;
** EDIT
MainPage.xaml.cs (NEW)
protected override void OnNavigatedTo(NavigationEventArgs e) { //Recent.ItemsSource = App.PictureList.Pictures; //Works with deleting, not sorted. if (Settings.AscendingSort.Value) { //Recent.ItemsSource = App.PictureList.Pictures.OrderBy(x => x.DateTaken).ToList(); //Recent.ItemsSource = new ObservableCollection<Models.Picture>(App.PictureList.Pictures.OrderBy(x => x.DateTaken)); App.PictureList.Pictures = new ObservableCollection<Models.Picture>(App.PictureList.Pictures.OrderBy(x => x.DateTaken)); //Error Recent.ItemsSource = App.PictureList.Pictures; } else { //Recent.ItemsSource = App.PictureList.Pictures.OrderByDescending(x => x.DateTaken).ToList(); //Recent.ItemsSource = new ObservableCollection<Models.Picture>(App.PictureList.Pictures.OrderByDescending(x => x.DateTaken)); App.PictureList.Pictures = new ObservableCollection<Models.Picture>(App.PictureList.Pictures.OrderByDescending(x => x.DateTaken)); //Error Recent.ItemsSource = App.PictureList.Pictures; } }
App.xaml.cs
public static PictureRepository PictureList { get { return PictureRepository.Instance; } }
PictureRepository.cs
#region Constants public const string IsolatedStoragePath = "Pictures"; #endregion #region Fields
source share