DragDrop DragEnter事件没有触发
问题非常奇怪,请各位高手帮忙分析一下,非常非常感谢有一段拖拽代码,经过调试后发现 DragEnter事件没有触发,界面的图标是个“禁止”的图标
但是奇怪的是
1、同一台机器,产品环境不能够拖拽,开发的代码环境可以拖拽(代码都是一样的)
2、这台机器开发环境之前也是可以拖拽,安装了一个产品,提示安装vsto4.0,安装过程失败才出现了这个问题
下面我贴出代码片段,请帮忙分析下:
BindingCellDataProvider<System.Windows.Controls.ItemsControl, Ctl.BindingNode> treeViewDataProvider =
new BindingCellDataProvider<System.Windows.Controls.ItemsControl, Ctl.BindingNode>("TreeViewItemObject");
NullDataConsumer<System.Windows.Controls.ItemsControl, Ctl.BindingNode> treeViewDataConsumer =
new NullDataConsumer<System.Windows.Controls.ItemsControl, Ctl.BindingNode>(new string[] { "TreeViewItemObject" });
BindingCellDataConsumer<Ctl.BindingNode> dataConsumer = new BindingCellDataConsumer<Ctl.BindingNode>(new string[] { "TreeViewItemObject" }, this);
new DragManager(this.chartView.DesignPane.BindingTree, treeViewDataProvider);
new DropManager(
this.chartView.DesignPane.BindingTree,
new IDataConsumer[] { treeViewDataConsumer });
new DropManager(
this.chartView.Cells,
new IDataConsumer[] { dataConsumer });
/// <summary>--------------------编程问答-------------------- 除 --------------------编程问答-------------------- AutoDrop设置为true了?
/// Manage data that is dragged over and dropped on the <code>dropTarget</code>.
/// Supported data is defined as one or more classes that implement IDataConsumer.
/// </summary>
/// <param name="dropTarget">FrameworkElement monitored for drag events</param>
/// <param name="dragDropConsumers">Array of supported data objects</param>
public DropManager(FrameworkElement dropTarget, IDataConsumer[] dragDropConsumers) {
this._dropTarget = dropTarget;
System.Diagnostics.Debug.Assert(dropTarget != null);
this._dragDropConsumers = dragDropConsumers;
System.Diagnostics.Debug.Assert(dragDropConsumers != null);
bool hookDragEnter = false;
bool hookDragOver = false;
bool hookDrop = false;
bool hookDragLeave = false;
// Determine which events to hook
foreach(IDataConsumer dragDropConsumer in this._dragDropConsumers) {
if((dragDropConsumer.DataConsumerActions & DataConsumerActions.DragEnter) != 0)
hookDragEnter = true;
if((dragDropConsumer.DataConsumerActions & DataConsumerActions.DragOver) != 0)
hookDragOver = true;
if((dragDropConsumer.DataConsumerActions & DataConsumerActions.Drop) != 0)
hookDrop = true;
if((dragDropConsumer.DataConsumerActions & DataConsumerActions.DragLeave) != 0)
hookDragLeave = true;
}
if((hookDragEnter == true) || (hookDragOver == true) || (hookDrop == true) || (hookDragLeave == true))
this._dropTarget.AllowDrop = true;
// Hook only the events needed
if(hookDragEnter == true)
this._dropTarget.DragEnter += new DragEventHandler(this.DropTarget_DragEnter);
if(hookDragOver == true)
this._dropTarget.DragOver += new DragEventHandler(this.DropTarget_DragOver);
if(hookDrop == true)
this._dropTarget.Drop += new DragEventHandler(this.DropTarget_Drop);
if(hookDragLeave == true)
this._dropTarget.DragLeave += new DragEventHandler(this.DropTarget_DragLeave);
}
/// <summary>
/// Initial call, after DoDragDrop is called, has Effects and AllowedEffects set to
/// allowedEffects as passed to DoDragDrop. Subsequent Effects and AllowedEffects
/// are set to the Effects returned by DragLeave. Note that DragLeave can return
/// effects that are not defined in allowedEffects (as passed to DoDragDrop).
/// Source and Original source are set to dragSource as passed to DoDragDrop.
/// </summary>
private void DropTarget_DragEnter(object sender, DragEventArgs e) {
DragDropEffects effects = e.Effects;
foreach(IDataConsumer dragDropConsumer in this._dragDropConsumers) {
if((dragDropConsumer.DataConsumerActions & DataConsumerActions.DragEnter) != 0) {
dragDropConsumer.DropTarget_DragEnter(sender, e);
if(e.Handled)
break;
}
}
if(!e.Handled) {
e.Effects = DragDropEffects.None;
e.Handled = true;
}
}
--------------------编程问答--------------------
设置了,忘记说了一个重点,拖拽的窗体是WPF,会不会是微软的bug,有没有人碰到过类似的问题 --------------------编程问答-------------------- 没人碰到过吗? --------------------编程问答-------------------- 没人知道吗??? 来个人,结贴给分!
补充:.NET技术 , ASP.NET