Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1865
Binding question
posted

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.

Parents
  • 6365
    Offline posted

    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");
        }
    }
     
    I have attached an MVVM based application that demonstrates the behavior from above. The changing of the DataItems is implemented with a Button Click (Click implemented by using the ICommand interface).

    If you require any further assistance on the matter, please let me know.

    XamDataGrid_MVVM.zip
Reply Children