ObservableCollection<object> selectedItemsCollection = newObservableCollection<object>();
PersonModel viewModel;
public MainWindow()
{
InitializeComponent();
viewModel = this.DataContext as PersonModel;
selectedItemsCollection.Add(viewModel.PersonDetails[1]);
selectedItemsCollection.Add(viewModel.PersonDetails[2]);
selectedItemsCollection.Add(viewModel.PersonDetails[3]);
selectedItemsCollection.Add(viewModel.PersonDetails[4]);
this.dataGrid.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
viewModel.SelectedItems = selectedItemsCollection;
} |