I have a xamDataGrid bound to ObservableCollection. I am using MVVM pattern. New items are added to the ObservableCollection by an event trigger implemented in the underlying VM class.
I am using:
App.Current.Dispatcher.Invoke(new Action(() => { _tradeSummary.Add(item); })); // _tradeSummary is the ObservableCollection
This works fine and I see the new Row added in the xamDataGrid.
However, when existing data items are changed in the ObservableCollection, I just can't get the existing rows in xamDataGrid to update. I tried using the same App.Current.Dispatcher.Invoke() and Notify(), but didn't work.
Please help.
P.S. If I put my data in a DataTable and bind to DataView, the existing data updates fine but then then new data rows don't show in the grid.
Hello Jay, Thank you for the code-snippet you have provided. In order for the XamDataGrid to update accordingly whenever you have changed the DataItems of the DataSource, you will need to implement the INotifyPropertyChanged interface for your DataItem class.
public string vmName{ get { return this.Name; } set { this.Name = value; // Comment to notice how the XamDataGrid // will NOT get updated. NotifyPropertyChanged("vmName"); }}
Thanks for the reply. I think, I am implementing the INotifyPropertyChanged interface the way you have mentioned. However, the collection is updated by an event that my class subscribes to. There are no methods and ICommand statements.
Shouldn't just firing NotifyPropertyChanged("vmName"); cause the entire grid to update. Note - as I mentioned, this works when new rows are added but not when existing data is changed.