我在使用可觀察集合的Silverlight數據網格時遇到問題。我已經創建了一個Silverlight數據網格,從WCF RIA服務中填充了一個可觀察的集合,並將一個集合綁定到網格。它第一次正常工作,但當我更改項目源內容時,數據不會在網格中刷新。當我雙擊datagrid單元格時,會顯示內容。我可能會缺少一些基本的屬性設置。任何人都可以幫忙嗎?刷新Silverlight DataGrid的問題
示例代碼:
App.BPIContext.Load(App.BPIContext.GetWellFieldListValuesQuery()).Completed += DataSource_WellFieldDataListValueLoadComplete;
ObservableCollection<ScheduleWellCustomFields> _userWellCustomFields = new ObservableCollection<ScheduleWellCustomFields>();
void DataSource_WellCustomFieldsLoadComplete(object sender, EventArgs e)
{
_userWellCustomFields.Clear();
App.BPIContext.ScheduleWellCustomFields.ToList().ForEach(c => _userWellCustomFields.Add(c));
this.dtGridDrillingEngineer.ItemsSource = _userWellCustomFields;
}
你改變的ObservableCollection的只是內容(即添加,刪除)還是您在DataGrid上設置了ItemsSource屬性?也許你期望你的數據發生變化。確保你爲這種情況拋出PropertyChanged。 –
我同意Joachim Kerschbaumer,在ScheduleWellCustomFields的屬性中設置NotifyPropertyChanged? –