XamDataGrid SelectedItems for MVVM

[Infragistics] Petar Monov / Monday, February 18, 2013

This is a simple approach (Grid_Binding_SelectedItems.zip) on how to add a bindable property to your XamDataGrid that can be used to control the SelectedItems from your view model.

In the sample I have made a View Model that has an ObservableCollection Data


and an IEnumerable SelectedData


In order to allow the XamDataGrid to get update from the SelectedData property and have him update the SelctedData property accordingly, I have added a


IEnumerable NewXDGSelectedItems


Dependency property to the XamDataGrid. Internally using the SelectedItemsChanged event I reset the NewXDGSelectedItems in order to trigger the PropertChanged. Also on the NewXDGSelectedItems’s ProeprtyChanged event, I tend to the SelectedItems.Records collection in order to keep the original behavior and have them update to the XamDataGrid.