I have drag and drop working in my application.
However, I have been running into an issue which I am not able to figure out whats causing it...
Basically, I have two itemsControl's where I am enabling drag and drop between them.
When the user drags items, I create a drag adorner and then do a drop preview on the control.
In some cases, when the drag adorner moves from source to the next itemsControl (i.e the target itemsControl where the drop will happen)...The OnPreviewDragLeave() method on the drag source
is not being called!
So the drag adorner just gets stuck on top of the source itemsControl.
This happens only in some cases, the only thing I can think of is that some other element is setting e.Handled to true maybe?
But how can I effectively debug this in an easy way as these events get fired continuosly and setting breakpoints is not really an option...
Any suggestions are appreciated,
thanks
Related
How can I make the drag & drop functionality activate faster? I want to shorten the duration between the mousedown and the drag and drop activating; so that the user is able to move the item faster.
I currently have it implemented using a ListView with CanDragItems set to true and AllowsDrop on my receiving Grid.
I have been searching, but I can't seem to find my answer anywhere.
I now have added a small animation when the item is touched (PointerPressed), which animates the view, so that the user has something to look at when they are waiting for the drag and drop to activate.
I have a ListView that acts as a drop target for drag and drop operations. When the list is empty, I place a TextBlock over top of it with a message informing users they can drag things there (both controls are contained in a single Grid cell to enable overlap). But... since the TextBlock is on top of the ListView, it intercepts the various events connected to drag and drop and prevents things from being dropped onto the message text itself.
I really don't want to add a drop handler to the TextBlock--is there any way I can simply make it "transparent" to drag and drop operations?
Something that just occurred to me while writing this which does work is to put the text below the list in the Z-order and then give the list a transparent background. But is this really the right way to achieve this? Ideally, there'd be a way to give the text one ZIndex for rendering, and a different one for hit testing.
Set IsHitTestVisible to False for TextBlock.
I'm dragging an item from a surfacelistbox over something else, let's say for example it's a normal wpf grid - how can I tell where (i.e. what column/row) the item has been dropped on?
Thanks a lot,
Dan
Put a Panel inside each cell of your Grid. The drop target will then be one of those panels
I'm using WPF here, I have some items in a list, which I can drag. As soon as you drag them I use:
DragDrop.DoDragDrop(this, new DragDropCommandItem(), DragDropEffects.Copy);
And animate-in a 'bin' over the UI where you can drag the item if you want to delete it. This all works well, except that I can't seem to do anything to detect when the user released the mouse so that I can hide the 'bin'. The second you call DragDrop.DoDragDrop it appears to release capture of the mouse. So even a system wide mouse down check returns false.
Is there any nice way to do this, or a way to query the drag state?
Any help would be appreciated, thank you.
I found this... I'll close the question now as I can use this solution.
How do I tell if a Drag Drop has ended in Winforms?
I have an app that incorporates a drop target to unarchive (file attribute) files. I would like to change the mouse cursor in the DragEnter event of the form to a custom cursor (.cur) that I have as an embedded resource.
The drop target is a transparent form with an image of a target. (The entire form is the drop target)
I know I can use the GiveFeedBack event when I have control of the drag source. However this is not the case as the source is Windows explorer. (and maybe I'm wrong and I can still use GiveFeedBack in this scenario, but I could not figure out how to trigger the event.)
To eliminate the possibility that my custom cursor was not valid or corrupt, I successfully set the custom cursor in the MouseOver event of the drop target form.
Functionally everything is working, I am now just wanting to "pretty things up" a little bit.
Thanks in advance for any insight.
You seem to know already that custom cursors are set in GiveFeedBack and how to do that. The problem then is that you are not getting any GiveFeedBack events. I don't know on what control you have a drop spot, but try attaching a listener to the underlying Form's GiveFeedBack event, and see if you get any feedback there.
You can also try subclassing the control you are using (Panel, PictureBox or whatever) and listening to its GiveFeedBack event.