使用Silverlight4工具包,是否可以从ListBox拖放到画布(并在拖放时将事件放到画布中)?
我能够编写代码将PanelDragDropTarget中的包装面板拖放到画布上,但事件处理程序不会在拖放发生时触发。当我试图从ListBoxDragDrop中的ListBox拖放到PanelDragDropTarget中的画布时,拖放没有发生(事件处理程序也没有触发)。在画布上拖动时,光标变为带有向上/向下箭头的光标。
谢谢,泰德
发布于 2011-12-01 22:25:33
出现此现象的原因是ListBoxDragDropTarget和PanelDragDropTarget的写入方式不同。当在两个ListBoxDragDropTargets之间拖动时,您正在传输绑定到控件的一段数据,而在两个PanelDragDropTargets之间拖动将传输被“拾取”的UIElement。
这就是为什么需要Dmitriyz的答案。PanelDragDropTarget检查您从ListBoxDragDropTarget拖出的元素是否是UIElement,因为它不是,所以它只是一段简单的数据,对于CanAddItem,它返回false。它会禁用丢弃的功能。因此,您可以看到带有向上/向下箭头的光标。
要让一切正常工作,您必须从PanelDragDropTarget继承并改用那个子类。它至少需要覆盖CanAddItem方法:
public class ElementDragDropTarget : PanelDragDropTarget
{
protected override bool CanAddItem(Panel itemsControl, object data)
{
return true;
}
protected override void InsertItem(Panel itemsControl, int index, object data)
{
// Do Work
}
}https://stackoverflow.com/questions/3772960
复制相似问题