Problems refreshing a Silverlight DataGrid
I am having a problem using a Silverlight data grid with an observeable collection. I have crated a Silverlight data grid, filled an observerable collection from WCF R开发者_JAVA技巧IA services and bound a collection to the grid. It works fine for the first time, but when I change the item source contents, the data is not refreshed in the grid. When I double-click on the datagrid cells, the contents are displayed. I may be missing some basic property settings. Can any one help?
Sample Code :
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;
}
Try to add this.dtGridDrillingEngineer.ItemsSource = null;
before his.dtGridDrillingEngineer.ItemsSource = _userWellCustomFields;
Get the binding object and force a refresh:
var bindingSource = TheDataGrid.GetBindingExpression(DataGrid.ItemsSourceProperty);
bindingSource.UpdateSource();
精彩评论