Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Grid not working properly for drag and drop

Tags:

c#

wpf

drag

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?

like image 980
TheJediCowboy Avatar asked Dec 06 '22 23:12

TheJediCowboy


1 Answers

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" ... />
like image 109
HCL Avatar answered Dec 11 '22 08:12

HCL