Sort and automatically orderly order updates

When I changed the value of the item linked in the list, I expected that the sorted order should automatically change.

But this is not so.

Am I calling the .SortDescriptions.Clear () method and redistributing the SortDescription in this case?

.Refresh () does not work.

EDITED

i linked and set the data as follows:

public Records myRecents; .... //lbToday is a ListBox. //ModifiedTime is a DateTime. this.lbToday.ItemsSource = new ListCollectionView(myRecents); this.lbToday.Items.SortDescriptions.Add(new SortDescription("ModifiedTime", ListSortDirection.Descending)); 

When the application was launched for the first time, it showed the correct result. But when I change the value of an element (in this case, the ModifiedTime property), the view does not change. And I ran the application again, and it again showed the correct result.

EDITED2

Here is the source code for Records .

 public class Records : ObservableCollection<RecordItem> { public Records() { } } 

and here is the source code for 'RecordItem'

 public class RecordItem : INotifyPropertyChanged { string queryString; public string QueryString { get { return queryString; } set { queryString = value; Notify("QueryString"); } } DateTime modifiedTime; public DateTime ModifiedTime { get { return modifiedTime; } set { modifiedTime = value; Notify("ModifiedTime"); } } public RecordItem() { } public RecordItem(string qStr) { this.queryString = qStr; this.modifiedTime = DateTime.Now; } public event PropertyChangedEventHandler PropertyChanged; protected void Notify(string propName) { if (this.PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propName)); } } } 

Note

When I added the item to myRecents (record class), it works well. There was a problem only with the property change.

+5
source share
1 answer

Take a look at this article from WPF Doctor: ItemsControl: 'E' for an editable collection.

This should help you with your problem.

+6
source

All Articles