I'm trying to make things a little more straight forward in an application I'm developing using drag and drop. I want to know if there is a way to apply the drag and drop to all items that have a particular style in xaml.
An example of this would be that I have a bunch of images, and I want them all to be draggable and droppable. I'm guessing there is some ability to create a template somehow.
Hi Joshua,
Let me know if you have any further questions on this.
I've attached a sample that demonstrates a pretty straight forward approach for doing this. I created a UserControl called DraggableImage and inside there is an Image which attaches DrapDropManager.DragSource object. This will allow us to drag the image. Then in my main application, instead of using the Image control I use my DraggableImage. I can create as many DraggableImage objects as I want and they will all be draggable.
In order to drop though, you need a DropTarget. I'm not sure how you want to handle this portion but I'd imagine you want to be able to drag all those images over to a specific location in your window. For instance a ListBox control. To do this you just need to attach the DragDropManager.DragTarget object to the ListBox and you will now be able to drag/drop the images onto the ListBox. You still need to handle the Drag/Drop events on the DragSource in order to perform the logic to add the image to the ListBox. This logic would go in the UserControl so you only have to handle the event once, not for each image you create.
Take a look at the sample and let me know if you have any questions.