Query Dragging state globally in Windows / DragDrop in WPF - c#

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?

Related

Clicking button makes Raycast go through to word space

I have an interactable ground like a network of hexagon tiles in my project. I am using a new UI system from Unity, UI toolkit, and clicking a UI button makes Raycast go through and interact with the tile below.
I read about some dirty solutions, but I believe there is a better solution than these:
https://forum.unity.com/threads/ui-toolkit-and-raycast-block.1034938/#post-8218593
In old UI system was something like EventSystem.current.IsPointerOverGameObject
Can anyone help me?
Is the clicked button working? If not you are probably missing raycast target. Make sure it is set to true on your button's image. If that's not the case you could try using:
UnityEngine.Event.current.Use();
in your buttons callback to consume the event and stop further execution.
I found the way to make EventSystem.current.IsPointerOverGameObject work.
I had a big #Screen VisualElement streching the whole screen. In the UI builder there is a property named PickingMode under the first inspector section. You just set it to ignore and it will not be detected.
If you want to check individual elements, I have no solution for that, but there is a method .Pick(Vector2) and I don't know how it works yet.
https://docs.unity3d.com/Manual/UIE-faq-event-and-input-system.html

Setup ListView as a drop target for files on Windows 10 Universal Apps

I have declared in my XAML the following element:
<ListView Name='mPlaylist' AllowDrop='True' DragEnter='HandlePlaylist_DragEnter' Drop='HandlePlaylist_Drop' />
When I drag a file from Windows Explorer or the desktop onto my ListView using the mouse, the DragEnter handler is executed and I can set the AcceptedOperation member of the DragEventArgs to Link (and Handled to true). So far, so good.
When I release left click, the Drop event handler is never fired. I can't figure out why not.
When I drag a file over the ListView, the cursor changes to a stop/invalid cursor, and the file thumbnail is overlaid with a red cross (despite my setting the AcceptedOperation to match one of the RequestedOperations - Link).
Although likely unrelated, the thumbnail also jumps up and to the left, a fair distance from the cursor. Moving the cursor over the ListView and the thumbnail does not maintain a constant distance from the cursor - I haven't been able to figure that out either.
I'm working on the PC, and using version 10.0.10069.0 of the Universal app platform in VS2015 RC.
Any ideas on what I can do to cause the Drop event to fire on my ListView (and perhaps even fix the visual glitch of the thumbnail 'separating' itself from the cursor when over the ListView) would be very much appreciated.
Solution is to use the DragOver event to set the AcceptedOperation member of the DragEventArgs, rather than DragEnter.
Thanks to Igor Ralic for posting the solution on his blog.

Debugging drag and drop in wpf?

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

How to change the drag and drop cursor when mouseover a drop target

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.

How to make "mouse-transparent" panel?

I'm new to WPF so I've got a problem:
I need to create a grid. This grid should contain a column with a kind of thumbnails.
When I move mouse over a thumbnail, there should appear a panel with a big image. This panel will cover all grid.
But this will make thumbnail think that mouse already has gone.
After mouse's gone, panel should dissappear. Mouse appears above thumb again, and panel appears. And again, and again. I don't know how to handle this.
Could anybody suggest any solution?
Sounds to me like you want to use IsHitTestVisible="False" on the image that pops up. This will make it ignore the popup when testing where the mouse is, so it will think your mouse is still over the thumbnail image. This should work on any UI element, except windows.
Use MouseEnter and MouseLeave:
http://www.hanselman.com/blog/MouseEnterAndMouseLeaveLoopsInWPF.aspx
There are two ways I can think of to do this, depending on what kind of functionality you're looking for.
If you want the larger image to appear in proximity to the mouse and the thumbnail, then you might want to take a look at using a Tooltip.
Otherwise as Aliostad mentioned above, you could use the MouseEnter and MouseLeave events to trigger the display of whatever content is needed.

Categories