繁体   English   中英

按日期排序ObservableCollection

[英]Sorting ObservableCollection by date

我有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; 
    ...
}

我需要通过ReminderDateTime对我的集合进行排序。 我尝试使用:IComparable但它没有用。

如果集合中的数据没有变化,如上所述,在绑定之前对集合进行排序将正常工作。 如果是(并且,从我的数据结构中,我猜是这样),那么这对于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>   

然后,将GridView绑定到CollectionViewSource

<GridView ItemsSource="{Binding Source ={StaticResource RemViewSource}}"></GridView>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM