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

drag & drop between usercontrols

6 Answers 179 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 09 Dec 2008, 10:32 PM

I use the page.xaml as the container for different usercontrols i have made. In the my middlecontrol i have a regular datagrid
which i have used this example http://www.telerik.com/community/forums/silverlight/drag-and-drop/drop-to-a-datagridrow.aspx
to drag the row items. But i also have a leftmenu control in which i have radtreeview, where i want to drop my grid row. i have the drag & drop logic in the middlecontrol but i have set the RadDragAndDropManager.SetAllowDrop(treeItem, true); on the treeviewitems in the leftmenu control . But the events in middlecontrols dosent trigger when i drop it on the treeviewitems. How should i set up the drag & drop manager to work with this?

6 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 10 Dec 2008, 12:12 PM

Hi Andreas Ekdahl,

The drag/drop events are routed events. They start travelling from the destination/target down to the root visual, Page.xaml. You can add handlers to a specific object along the way of the event or add a ClassHandler (as I have done for the Treeview items in the example you mentioned).

I think the problem may be that the TreeView Drop handlers are added to the DataGrid (middle) page.

You can add the handlers to the root Page.xaml or move the TreeView-specific handlers to the left UserControl.

Kind regards,

Miroslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Andreas
Top achievements
Rank 1
answered on 10 Dec 2008, 02:46 PM
Hey,
I did as you said and moved the TreeView-specific handlers to the left UserControl. and now the OnDropQuery works when i drag grid item over the tree item. But when i release the mouse to drop it in there the OnDropInfo event never triggers. What have i missed here?
0
Andreas
Top achievements
Rank 1
answered on 10 Dec 2008, 03:07 PM
Now i moved all event handling stuff to the root page instead so that everything is handled from one place. All events get triggered except for the OnDropInfo as my previous post.
0
Miroslav
Telerik team
answered on 10 Dec 2008, 04:07 PM

Hello Andreas,

This seems a bit odd.

  • Could you check that you are returning a positive result in the DragQuery and DropQuery handlers? (The e.QueryResult == true).
  • After returning a positive result, it is best to handle the event (e.Handled = true) so that parent nodes will not return a negative result.
  • To do a drop, the source and the destination need to accept it.
  • Also, you can add a Class handler for the DropInfo event and check whether it is fired at all.

I will be happy to look at a sample project and identify the problem.

Greetings,

Miroslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Andreas
Top achievements
Rank 1
answered on 10 Dec 2008, 11:05 PM
Hey, yes i forgot to set e.QueryResult = true and e.Handled = true on the correct places. the drag & drop control is sweet.
Another question is. How can i add a image when going over the treeitem and make it disapear when
going away from the treeitem? i dont know how i should hook that up.
0
Miroslav
Telerik team
answered on 11 Dec 2008, 09:37 AM
Hi Andreas,

You can give feedback to the user by handling the DropInfo event and check for the DropPossible / DropImpossible status. There you have access to the DragCue that you set when the drag started.

You can add and remove objects to the DragCue and the ArrowCue. For example you can change the background color of the arrow to red/green depending on when the drop is possible or not. You can set any control as the DragCue (I often use DragDropManager.GenerateDragCue() but only because it is quick). You can even add a user control there, with images, text and whatever you need.

This may be the easiesrt way to add feedback. You have access to the TreeView item as well but it may be best not to try to add/remove visual items from it while dragging. This will help keep the drag/drop handlers more generic as well.

Best wishes,
Miroslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
DragAndDrop
Asked by
Andreas
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or