从ListBoxDragDropTarget拖放到PanelDragDropTarget [英] Drag/drop from ListBoxDragDropTarget to PanelDragDropTarget
问题描述
使用Silverlight 4工具包,是否可以从ListBox拖放到Canvas(并将Canvas上的一个事件放到Canvas中)?
Using the Silverlight 4 toolkit, is it possible to drag and drop from a ListBox to a Canvas (and get an event on the drop into the Canvas)?
我能够编写一个代码来将一个PanelDragDropTarget中的wrap panel拖放到canvas中,但事件处理程序在发生drop时没有触发。当我试图将ListBoxDragDrop中的ListBox拖放到PanelDragDropTarget内的Canvas时,没有发生掉落(并且事件处理程序没有触发)。在拖动画布的同时,光标变成了上/下箭头的光标。
I was able to write code to drag/drop from a wrap panel inside a PanelDragDropTarget to a canvas but the event handler did not trigger when the drop occurred. When I tried to drag/drop from a ListBox inside a ListBoxDragDrop to the Canvas inside the PanelDragDropTarget, the drop did not occur (and the event handler didn't trigger). While dragging over the Canvas, the cursor turned into the one with up/down arrows.
谢谢Ted
推荐答案
在Mohamed的帖子中描述的步骤还有一点问题。当您将鼠标悬停在目标面板元素上时,拖放指示器看起来像滚动操作(并且我需要一个带箭头的移动操作)。为了避免这种影响,我创建了一个派生自PanelDragDropTarget的类,我在这里覆盖了导致问题的两种方法。
After the step described in the Mohamed's post there's still a little problem. When you hover over the target Panel element the drag-and-drop indicator looks like one for the scroll operation (and I needed the one with an arrow - for move operation). To ger rid of that effect I created a class derived from PanelDragDropTarget where I overrode two methods that caused the problem.
public class FixedPanelDragDropTarget : PanelDragDropTarget
{
protected override bool CanAddItem(Panel itemsControl, object data)
{
return true;
}
protected override void InsertItem(Panel itemsControl, int index, object data)
{
//
}
}
之后在FixedPanelDragDropTarget.Drop事件的处理程序中,我们可以手动创建一个删除元素的意图而其余的看起来应该是这样的。
After that in the FixedPanelDragDropTarget.Drop event's handler we can manually create an intance of the dropped element, while the rest looks like it was supposed to.
这篇关于从ListBoxDragDropTarget拖放到PanelDragDropTarget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!