drag & drop between usercontrols

7 posts, 0 answers
  1. Andii
    Andii avatar
    17 posts
    Member since:
    Nov 2006

    Posted 09 Dec 2008 Link to this post


    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?
  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 10 Dec 2008 Link to this post

    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.
  3. DevCraft banner
  4. Andii
    Andii avatar
    17 posts
    Member since:
    Nov 2006

    Posted 10 Dec 2008 Link to this post

    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?
  5. Andii
    Andii avatar
    17 posts
    Member since:
    Nov 2006

    Posted 10 Dec 2008 Link to this post

    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.
  6. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 10 Dec 2008 Link to this post

    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.
  7. Andii
    Andii avatar
    17 posts
    Member since:
    Nov 2006

    Posted 10 Dec 2008 Link to this post

    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.
  8. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 11 Dec 2008 Link to this post

    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.
Back to Top
DevCraft banner