2011-09-10 41 views
5

Khi tôi sửa đổi giá trị của một mục bị ràng buộc trong hộp danh sách, tôi dự kiến ​​một thứ tự sắp xếp sẽ tự động thay đổi.SortDescription và tự động sắp xếp thứ tự làm mới

Nhưng không.

Tôi có gọi phương thức .SortDescriptions.Clear() và phân bổ lại một SortDescription trong trường hợp này không?

.Refresh() không hoạt động.

EDITED

tôi bị ràng buộc và setted các dữ liệu như thế này;

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)); 

Khi ứng dụng được khởi chạy trong lần đầu tiên, nó cho thấy kết quả chính xác. Nhưng khi tôi modfying một giá trị của mục (trong trường hợp này, 'ModifiedTime' tài sản), một cái nhìn không thay đổi. Và tôi đã khởi chạy lại ứng dụng, nó hiển thị kết quả chính xác một lần nữa.

EDITED2

Đây là một mã nguồn của Records.

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

} 

và đây là một mã nguồn của '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

Khi tôi thêm một mục trong myRecents, (Record lớp), nó hoạt động tốt. Đã xảy ra sự cố chỉ thay đổi thuộc tính.

+0

bạn có thể cho biết cách bạn ràng buộc dữ liệu với kiểm soát giao diện người dùng không? –

+0

Tất nhiên. đợi tí. – mjk6026

Trả lời

Các vấn đề liên quan