WPF Drag and Drop - Get original source info from DragEventArgs

Posted by Quinn351 on Stack Overflow See other posts from Stack Overflow or by Quinn351
Published on 2010-12-23T12:44:14Z Indexed on 2010/12/23 12:54 UTC
Read the original article Hit count: 281

Filed under:
|
|
|

I am trying write Drag and Drop functionality using MVVM which will allow me to drag PersonModel objects from one ListView to another.

This is almost working but I need to be able to get the ItemsSource of the source ListView from the DragEventArgs which I cant figure out how to do.

private void OnHandleDrop(DragEventArgs e)
{
    if (e.Data != null && e.Data.GetDataPresent("myFormat"))
    {
        var person = e.Data.GetData("myFormat") as PersonModel;
        //Gets the ItemsSource of the source ListView
        ..

        //Gets the ItemsSource of the target ListView and Adds the person to it
        ((ObservableCollection<PersonModel>)(((ListView)e.Source).ItemsSource)).Add(person);
    }
}

Any help would be greatly appreciated.

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf