I found the answer to another question
The way to do this is to pass the original ListView to the DragDrow.DoDragDrop method, i.e.
In the method that handles PreviewMouseMove for ListView do -
private static void List_MouseMove(MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { if (e.Source != null) { DragDrop.DoDragDrop((ListView)e.Source, (ListView)e.Source, DragDropEffects.Move); } } }
and then in the OnHandleDrop method change the code to
private static void OnHandleDrop(DragEventArgs e) { if (e.Data != null && e.Data.GetDataPresent("System.Windows.Controls.ListView")) { //var person = e.Data.GetData("myFormat") as PersonModel; //Gets the ItemsSource of the source ListView and removes the person var source = e.Data.GetData("System.Windows.Controls.ListView") as ListView; if (source != null) { var person = source.SelectedItem as PersonModel; ((ObservableCollection<PersonModel>)source.ItemsSource).Remove(person); //Gets the ItemsSource of the target ListView ((ObservableCollection<PersonModel>)(((ListView)e.Source).ItemsSource)).Add(person); } } }
source share