-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drag-Drop improvements #7556
Comments
It might help to emphasize these issues come from real-world use cases -- my guess when implementing/testing the TabView port. |
For 4. above, my use case is: the user has to be able to drag and drop something, and once they start dragging it, a visual copy of the element follows the user's cursor around until they drop it (see tab dragging in Firefox for an example). Generating the visual copy is easy enough, but when attempting to move it to follow the user's cursor, I too ran into the issue where subscribing to the raw events didn't work:
On Windows, I believe this thread about the same problem in WPF highlights the challenge:
I successfully used the workaround as highlighted here, again for WPF:
Setting Then you would determine manually if the pointer is over your actual drop targets like this:
Definitely hacky, but it does work. |
I'm now using the approach referenced here, and with a full reference implementation here. The hooked mouse events are sent back into the IInputManager so that subscribing to the IInputManager like
Is there any appetite to put this into Avalonia? Presumably it would look something like this, although I don't know the best way to get access to the appropriate
I'm happy to open a PR if this is approach is acceptable. I have no idea who to reference here, apologies if this is a bit wide. @robloo @grokys @maxkatz6. |
I've done some more investigating into this, particularly (4). The InputManager returning (-1,-1) is only occuring because the wrong RawEvent is being queried. If you use UWP does have Also an aside, |
I think Avalonia needs a way to allow/not allow drag and drop from code. This would be better explained in a scenario: |
Thank you!! I was about to give up but this clued me in to fixing my dnd!! Spent the last 2 ENTIRE days racking my brain because my dnd broke dragging into external applications. But only for 1 type of control and its because of a freakin' tooltip I added! (its only conditionally visible but was still directly attached to a parent of the drag source) This situation does more than just make the cursor flicker (only testing on Win11 right now) it'll invalidate the whole operation. So to fix I moved the tooltip into a style so its only attached if not dragging. Thank you man |
Is your feature request related to a problem? Please describe.
A couple issues I've come across with drag-drop (in-app, not to/from external process):
1 - IMO, the drag-drop events really need to sit in one of the base classes to all controls like it is in WPF/UWP (in UIElement). There are some cases where being able to do some logic before or after one of the drag events is raised is super helpful (thus needing a protected virtual method) as you can't rely on AddHandler() to do, particularly in the latter case.
2 - If a control that acts as a drag source contains a
ToolTip
, theToolTip
needs to be hidden as part of drag drop activating, which follows WPF. Otherwise, the ToolTip will hide, but the drag/drop icon flickers as the pointer moves.3 -
DragLeave
event should haveDragEventArgs
instead of justRoutedEventArgs
- so pointer information can be retrieved4 - One of the things I also was trying to implement, similar to UWP dragging, is a popup with a preview of the item being dragged - except it seems the popup doesn't respond to the changes in position during drag drop.
popup.Host.ConfigurePosition()
is called but the popup remains in one place. It also seems that all of the InputManager methods (process, preprocess, postprocess) don't do anything during drag drop and return (-1,-1) only once upon queryingRawPointerEventArgs.Position
, which makes this task impossible to achieve in any way that I can see. I've tested with WPF and this is possible5 Current implementation preprocess events in global static IInputManager to simulate dnd
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: