简体   繁体   English

WPF网格无法正常拖放

[英]WPF Grid not working properly for drag and drop

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. 所以基本上它是一个List,但这并不是那么重要。

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). 第一个网格包含一个标签,第二个网格包含一个组件,如TextBox或DropDown框。(它是一个用于构建HTML表单的拖放编辑器)。

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. 我遇到的问题是当我拖过网格的子元素时,DragOver,DragDrop等只会触发。 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? 我需要在Grid Element上设置一些允许整个Grid接受丢弃的内容吗?

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" ... />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM