WPF:单元格之间的网格拖放控件 [英] WPF: Grid drag and drop controls between cells

查看:92
本文介绍了WPF:单元格之间的网格拖放控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有动态创建的行和列的网格.我向这些单元格添加了自定义控件,有些控件跨越了多个单元格.我还使用Adorner将控件从一个单元格移动到另一个单元格.我可以将它们拖动,但无法找到将它们放到哪个单元格.

关键字:wpf,网格,单元格,网格,鼠标悬停,拖动,拖放


I have a Grid with the dynamically created rows and columns. I add custom controls to the cells, and some get spanned across several cells. I also use an Adorner to move the controls from one cell to another.  I can drag them but I cannot find out to which cell they were dropped.

preview

1. If I just use the cells (without adding the panels (that could catch the mouse over even)), the only way that I can get the location of the drop is to get the relative location of the mouse cursor and go through the widths and heights of the rows and columns and see where the mouse position fits. But I do not have a good feeling about doing it this way.

2. If I put the basic panels in each cell, it seems that the adorner (while dragging) blocks the MouseOver event of the panels in the cells and panels do not get mouse over event fired.

I must use the grid because I need to span some of the rows or/and columns, so changing the grid into something else is not the option. There is probably a way to make it work with the adorner, so if someone would help me, I would really appreciate that.

Thanks

keywords: wpf, grid, cells, grid, mouseover, drag, drop


推荐答案

我认为使用面板可能不是一个好的设计,因为控件应该可以跨越多行或多列,并且面板可能会使它复杂化.此外,由于WPF网格控件不具有按位置获取单元格的内置功能,因此我们只能通过自行计算鼠标位置来做到这一点.

I think that use panel may be not a good design, because the controls should can span multiple rows or columns, and a panel may complicate this. Futhermore, because WPF grid control does not have the build-in functionality for getting the cell by position, so we can only do this by calculate the mouse position by ourself.

最好的问候,

韦州


这篇关于WPF:单元格之间的网格拖放控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆