如何排序列表框项?

时间:2013-11-28 11:40:59

标签: windows-phone-7 sorting listbox

我只是想知道是否有办法对列表框中的项目进行排序,例如按字母顺序降序,升序?到目前为止,这是我的代码,它基本上将文件添加到列表框中:

 Dim Storage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
    Dim directory As String = "./MyNote/SavedNotes/*.*"
    Dim filenames As String() = Storage.GetFileNames(directory)
    Dim dataSource As New List(Of SampleData)()
    For Each filename As String In filenames
        Dim ISF As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
        Dim FS As IsolatedStorageFileStream = ISF.OpenFile("MyNote/SavedNotes/" & filename, FileMode.Open, FileAccess.Read)
        Using SR As New StreamReader(FS)
            Dim FTime As String = GetRelativeTime(Storage.GetCreationTime("MyNote/SavedNotes/" & filename).ToString)
            Dim DATESS As String = SR.ReadLine
            Dim ReadName As String = SR.ReadLine
            dataSource.Add(New SampleData() With {.FileNameX = filename, .Description = ReadName, .FileTime = FTime})
        End Using
    Next
    SavedNotesList.ItemsSource = dataSource

我只是想知道如何按字母顺序对添加的项目进行排序?有人能帮我吗?我听说需要一个可观察的收集或某种类型的收集?

1 个答案:

答案 0 :(得分:1)

你很容易做到

 Dim query As IEnumerable(Of SampleData) = _
            datasource.OrderBy(Function(SampleData) s.FileNameX )