Currently I have in my XAML
<TabControl
AllowDrop="True"
PreviewDragOver="DragOver"
PreviewDrop="Drop" />
All of my drag/drop code exists within the codebehind of my View, rather than within my ViewModel.
How can I handle drag/drop in my ViewModel without adding any dependencies on the View?
There are libraries for this such as gong and similar snippets on various blog articles.
However, you shouldn't get too hung up on having absolutely no code-behind. For example, this is still MVVM in my book:
A command binding might be a better choice, but the logic is definitely in the viewmodel. With something like Drag and Drop, it's more variable where you want to draw the line. You can have code-behind interpret the Drag Args and call methods on the viewmodel when appropriate.
This is just an additional answer that ports @Asheh's answer's to VB.NET for VB developers.
This might also be of some help to you. The attached command behavior library allows you to convert any event(s) into a command which will more closely adhere to the MVVM framework.
http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/
Using this is extremely easy. And has saved my bacon numerous times
Hope this helps
Here is some code I wrote that allows you to drag and drop files onto a control without violating MVVM. It could easily be modified to pass the actual object instead of a file.
Usage:
Ensure the DataContext inherits from IFileDragDropTarget and implements the OnFileDrop.