1

I have ObservableCollection AllRem

public sealed class GetRem
{
    public static string RemIDForNot;
    public string ReminderColor = "1";
    public int RemID { get; set; }
    public string ReminderName { get; set; }
    public string ReminderDescription { get; set; }
    public DateTime ReminderDataTime { get; set; }
    public Boolean? ReminderDone = false; 
    ...
}

I need to sort my collection by ReminderDateTime. I tried using :IComparable but it did not work.

SuxoiKorm
  • 159
  • 2
  • 11

1 Answers1

0

Sorting the collection before binding, as suggested above will work fine, if the data in the collection is not changing. If it is (and, from your data structure, I would guess so), then this becomes a good scenario for a CollectionViewSource

<UserControl.Resources>
    <CollectionViewSource Source="{Binding DS.AllRem}" x:Key="RemViewSource" IsLiveSortingRequested="True" >
        <CollectionViewSource.SortDescriptions>
            <componentModel:SortDescription PropertyName="ReminderDataTime" Direction="Descending"/>
        </CollectionViewSource.SortDescriptions>
    </CollectionViewSource>
</UserControl.Resources>   

Then, bind the GridView to the CollectionViewSource

<GridView ItemsSource="{Binding Source ={StaticResource RemViewSource}}"></GridView>
r_c
  • 176
  • 7
  • Yes, I need collection changing. But I do not understand how use CollectionViewSource. I have GridView with Bind to my collection ItemsSource="{x:Bind DS.AllRem, Mode=OneWay}" Where i need to use CollectionViewSource? – SuxoiKorm Jun 21 '16 at 21:03
  • Basically, the structure becomes CollectionViewSource.Source bound to ViewModel property GridView.ItemSource bound to CollectionViewSource. I'll edit my answer to provide the full structure – r_c Jun 21 '16 at 23:44
  • I have error message The property 'IsLiveSortingRequested' was not found in type 'CollectionViewSource' and other related whit this propertie – SuxoiKorm Jun 22 '16 at 18:09
  • You need a namespace reference. Put the following in your UserControl/view declaration xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase" – r_c Jun 23 '16 at 01:34
  • Did not help. Can the UWP does not support? – SuxoiKorm Jun 23 '16 at 20:21
  • don't have any idea? – SuxoiKorm Jun 28 '16 at 20:11
  • Barely. Quick google suggests that in UWP the sorting is enabled on the CollectionView (not ViewSource) - which is, in this case the DataGrid or ItemCollection. Could you post your view code/markup? – r_c Jun 29 '16 at 00:09
  • I share my mainpage.xaml https://1drv.ms/u/s!Almt2-yL8xeklatuWRdel-TEXjLPrQ – SuxoiKorm Jul 03 '16 at 14:30