This is what I did after I made the same script as you. In the short handle, the selection event will change directly and pull the selected rows from the event arguments. Suppose that the original set of "Strings" each of them is a RowViewModel and a collection for "_selectedRows".
<DataGrid RowsSource="{Binding Rows}" x:Name="Rows" SelectionMode="Extended" SelectionUnit="FullRow"> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <cal:ActionMessage MethodName="SelectedRowsChangeEvent"> <cal:Parameter Value="$eventArgs" /> </cal:ActionMessage> </i:EventTrigger> </i:Interaction.Triggers> </DataGrid>
public void SelectedRowsChangeEvent(SelectionChangedEventArgs e) { foreach (var addedRow in e.AddedRows) { _selectedRows.Add(addedRow as RowViewModel); } foreach (var removedRow in e.RemovedRows) { _selectedRows.Remove(removedRow as RowViewModel); } }
source share