This is a migrated thread and some comments may be shown as answers.

Detect if key is pressed

3 Answers 100 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Alex Galie
Top achievements
Rank 2
Alex Galie asked on 13 Jan 2010, 11:07 AM
Hello all,

I'm currently using the RAD controls for silverlight and I'd like to implement the following: when I drag an item from one place to another, detect if a key, for example shift, is pressed, while dragging that is. Depending on this, I want to change the drag cue, if possible, and also, more importantly, choose what logic to follow when dropping the item.

Is this achievable ?

Thanks!

3 Answers, 1 is accepted

Sort by
0
Accepted
Miroslav
Telerik team
answered on 14 Jan 2010, 12:29 AM
Hello Alex Galie,

Yes, it is possible to detect if any of the special keys is pressed by checking Keyboard.Modifiers.

If you assign a drag cue element to the e.Options.DragCue in any of the DragDrop handlers, you will be able to access it and change any of its properties to give it a different look.

I can suggest using the TreeViewDragCue control that is used by the TreeView for its DragDrop. This class has built-in properties that help you display DragDrop information.

I am attaching an example that shows how this control can be used in custom scenarios. The particular example does not show integration with the keyboard modifiers so do get back to us if you have problems implementing this.

All the best,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alex Galie
Top achievements
Rank 2
answered on 14 Jan 2010, 09:56 AM
Thanks Miroslav, it works.

There is a small issue however: where should I test for Keyboard.Modifiers to reflect the changes in "real time" ? Right now, I've put it in DropInfo handler and it's something like this:

if (e.Options.Status == DragStatus.DropPossible) 
    if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) 
    { 
            // change cue here 
        } 
 

If I just hold the dragged item still and press Control, nothing happens, I have to move it a bit for the cue to change. Is there a way to change the cue right when Control is pressed and I'm not moving the dragged item around ?

Don't know if it's clear, hope you understand what I'm trying to say :)


Thanks,
Alex
0
Miroslav
Telerik team
answered on 15 Jan 2010, 06:04 PM
Hello Alex Galie,

Yes, it is clear what you are trying to achieve.

To care for this case you may handle the KeyDown event in your application root and access the DragDrop options object from RadDragAndDropManager.Options. This is the same options object that you will get in the event handler.

In fact you can move most of your update logic there apart from the things that happen on DropComplete.

You can use RadDragAndDropManager.IsDragging to check whether updates are necessary.

Please note that events may not always reach the application visual roots, especially if the happen in popups. Do test this if it matters in your case. 

Hopefully this will work for you.

Greetings,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
DragAndDrop
Asked by
Alex Galie
Top achievements
Rank 2
Answers by
Miroslav
Telerik team
Alex Galie
Top achievements
Rank 2
Share this question
or