views:

29

answers:

2

Hi,

I have a Canvas which is present in a usercontrol, I have attached the DoubleClick event to this user control like this

mainWindow.CanvasLayout.MouseDoubleClick += 
new MouseButtonEventHandler(CanvasLayout_MouseDoubleClick);

I am usign this event handler to achieve fullscreen functionality.

Now, canvas can have various controls placed inside it. Drag and drop functionality is implemented for these controls similar to this codeplex article -

http://www.codeproject.com/KB/WPF/WpfDragAndDropSmorgasbord.aspx

Basically i handles these events for a control -

this._dragSource.PreviewMouseLeftButtonDown +=
new MouseButtonEventHandler(DragSource_PreviewMouseLeftButtonDown);
this._dragSource.PreviewMouseMove += 
new System.Windows.Input.MouseEventHandler(DragSource_PreviewMouseMove);
this._dragSource.PreviewMouseLeftButtonUp += 
new MouseButtonEventHandler(DragSource_PreviewMouseLeftButtonUp);

Now, when user double click on a control(present in canvas) both double click(FullScreen) and single click(drag & drop) operations are performed, i.e. if user double click on control and change its mouse position quickly, control position is changed(its draggeed and dropped to new position).

Is there any way I can prevent drag and drop operation when user double clicks on a control?

A: 

What you need to do is, on mouse up start a timer the time should be retrieved from SystemInformation.DoubleClickTime, and do the click action on the timer tick (only if you didn't detect the double click in the mean time, obviously).

Likewise use SystemInformation.DragSize to prevent accidental drag&drop.

Note, the SystemInformation class is part of WinForms so you need to add a reference to System.Windows.Forms, this class will work just fine in WPF apps.

Nir
Thanks Nir, I was planning to try the timer but was able to solve the problem without it.
akjoshi
+1  A: 

Got it, Instead of handling MouseDoubleClick event I did this -

mainWindow.CanvasLayout.PreviewMouseLeftButtonDown 
+= new MouseButtonEventHandler(CanvasLayout_PreviewMouseLeftButtonDown);

and

void CanvasLayout_PreviewMouseLeftButtonDown(object s, MouseButtonEventArgs e)
{
    if (e.ClickCount > 1)
    {
        // Do double-click code  
        // Code for FullScreen 
        e.Handled = true;
    }
}
akjoshi