Quantcast
Viewing latest article 3
Browse Latest Browse All 801

Commented Issue: ListBoxDragDropTarget misses mouse up event occasionally [5930]

In the April 2010 release I've noticed that code that used to work fine in the March 2010 release is now behaving strangely. I have a ListBox that is wrapped in a ListBoxDragDropTarget element. When I click on an item in the list box to select it, sometimes a drag operation is started even though I did not hold down the mouse button. It seems to be fairly repeatable but not consistent. I can't detect a pattern.
 
Inside the ListBoxItem is an object which is listening to mouse events for detecting double click so I will investigate that and report back but I just wanted to post this in case anyone else is noticing the same thing.
Comments: ** Comment from web user: 70sCommander **

__Hello Community,__

the workaround provided by __bigfootsoft__ fixed our problem without using timers! (which are always no solution to the problem!)
Here is the code:

```
using System.Windows.Input;
using Microsoft.Windows;

namespace XYZ.Controls.TreeView
{
using Nodes;
using XYZ.Nodes;
using XYZ.Nodes.StaticNodes.AnchorNodes;
using System.Windows.Controls;

public class XYZTreeViewDragDropTarget : TreeViewDragDropTarget
{
private bool leftButtonUp = false;
private bool hasQueriedContinueDrag;
private bool cancelDrag;

public XYZTreeViewDragDropTarget()
{
AddHandler(MouseLeftButtonUpEvent, new MouseButtonEventHandler(HandleMouseLeftButtonUp), true);
AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(HandleMouseLeftButtonDown), true);
}

private void HandleMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
hasQueriedContinueDrag = false;
cancelDrag = false;

base.OnMouseLeftButtonDown(e);
}

private void HandleMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (!hasQueriedContinueDrag)
cancelDrag = true;

base.OnMouseLeftButtonUp(e);
}

protected override void OnQueryContinueDrag(QueryContinueDragEventArgs args)
{
hasQueriedContinueDrag = true;

if (cancelDrag)
{
args.Action = DragAction.Cancel;
args.Handled = true;
}
base.OnQueryContinueDrag(args);
}
}
}
```


Viewing latest article 3
Browse Latest Browse All 801

Trending Articles