Hi,
I have a ViewModel that has a property, ReactiveList SelectedItems, which I want to bind to the SfDataGrid.SelectedItems property.
It needs to be a two way binding:
- when a user selects multiple items on the SfDataGrid, my ViewModel should receive notification that the collection of selected items has changed.
- if I programmatically set ViewModel.SelectedItems, then the SfDataGrid should reflect this selection.
- The binding is only one way, and badly implemented since it creates a new ObservableCollection each time, rather than updating the existing ObservableCollection. By recreating the ObservableCollection each time, any existing handlers attached to the ViewModel property will no longer work. Also, as noted in the comments below the article, 'The OnSelectedItemsChanged method is called multiple times after the first selection. This effectively renders any usage impractical.'
- It uses an ObservableCollection, not a ReactiveList.
Also, I am unable to test whether this particular approach works with ReactiveLists, or works in a two way fashion.
How can I achieve this without breaking MVVM?
Cheers,
James.