I'm writing a user control in WPF which is based on a ListBox. One of the main pieces of functionality is the ability to reorder the list by dragging the items around. When a user drags an item I change the items Opacity
to 50% and physically move the item in an ObservableCollection
in my ViewModel depending on where the user wants it. On the drop event I change the Opacity
back to 100%.
The problem I've got is that if the user drags the item off my control and drops it somewhere else then I need to change the Opacity
back to 100% and move the item back to where it was when the user started the drag. Is there an event I can handle to capture this action? If not is there any other cunning way to solve this problem?
Assuming you are using the built-in drag and drop functionality, you can use the return value of the DoDragDrop method. If the drop target does not accept the dragged object, then DoDragDrop returns DragDropEffects.None.
This of course assumes that the other controls on your form do not allow the dropping of your list items.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With