Rebinding to ObservableCollection

On my Window DataContext I set to a ViewModel, then I set my grids ItemsSource to my ObservableCollection property.  I instantiate the Window, and my gird is filled out with the correct data, to the binding is working.

Next I add 4 blank records, but I dont want them, so I clear my ObservableCollection and reload from Database, all is good, my ObservableCollection has now been reset with the correct data, the DataContext of my Window also show the correct amount of data, but the underlying source of the DataGrid shows an ItemSource with 0 records, even though it is bound to my collection.

Why is this?  If I add/delete/change the data gets updated correctly and saved back to the database, but if I totally clear the collection and reload it my ItemSource never gets updated with the refreshed data from the database.

Any help would be appreciated.  Thanks.

3 Replies

DY Deivaselvan Y Syncfusion Team August 23, 2018 12:01 PM UTC

Hi Luke,

Thank you for contacting Syncfusion support.

From the given update, we could suspect that you have not inherited your ViewModel class with the INotifyPropertyChanged interface, causes the collection reset to the property which is bound with the ItemsSource of DataGrid is not reflected. Can you try to inherit the ViewModel class with the interface of INotifyPropertyChanged and implement its event for the Properties in ViewModel and let us know if this helps you.

If you still reproduce the issue, then could you please share your ViewModel and XAML details for analyzing further and update you with the appropriate details at the earliest.

Regards,
Deivaselvan 



LU luke August 23, 2018 12:36 PM UTC

Thanks, I overlooked raising it for my Property, not just internal to the ObservableCollection.  It is working.


DY Deivaselvan Y Syncfusion Team August 23, 2018 06:45 PM UTC

Hi Luke,

We are happy to know that you have achieved your requirement with the given details. Please let us know if you require any further assistance.

Regards,
Deivaselvan 


Loader.
Up arrow icon