WPF Grid not working properly for drag and drop
Asked Answered
I

2

7

I am working with an application that uses drag and drop operations of grids. The application is backed by a List of objects. When a grid is dropped, the children of the grid(my data) are added to the list. So essentially it is a List but that is not really that important.

Each Grid contains two inner grids. The first grid contains a label, and the second contains a component such as a TextBox, or a DropDown box.(It is a drag and drop editor for building HTML Forms).

I am working on making it easier for the user to see when they drag over the grids if they are going to drop above, below or on the element by checking the position of the mouse while they are dragging over the grid elements.

The problem I am running into is that the DragOver,DragDrop,etc are only firing when I drag over the child elements of the grids. I have tried to go from bubbling to tunneling and vice versa but I cant figure it out.

Is there something I need to set on the Grid Element that allows the entire Grid to accept drops?

Indulge answered 14/2, 2011 at 20:52 Comment(1)
Does this answer your question? WPF: Canvas mouse events not firing on empty spaceSur
E
20

Try setting the background of your grids to a transparent brush. In this case I'm not sure if this is the problem, but for most mouse operations such as hit tests, you have to attach a background even if it is transparent.

<Grid Background="Transparent" ... />
Ecklund answered 14/2, 2011 at 20:58 Comment(1)
this worked! Thank you, I figured that as long as I was handling the event through the grid, that it would have been fine.Indulge
S
1

In my case, VS and File Explorer were opened with different privilege levels (ie, admin and user), and I could not drag and drop files from the latter to the former.
This post solved it for me.

Strychnic answered 21/6, 2023 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.