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.
mjk6026
source share