Multiple Target DragAndDrop

4 posts, 1 answers
  1. Andrei
    Andrei avatar
    7 posts
    Member since:
    Jan 2013

    Posted 05 Nov 2014 Link to this post


    I have a drag drop setup between a RadListBoxA (type A objects) and  a ScheduleView(Appointments)

    I use OnDragInitialize on the ListBox like this:
    private void OnDragInitialize(object sender, DragInitializeEventArgs args)
                var leg = ((sender as ContentControl).Content as TransportOrderLegViewModel);
                // Convert Data to ScheduleView Payload
                var appt = new Appointment() {  };
                if (leg.Planned)
                    appt.Location = "Test";
                var payload = new ScheduleViewDragDropPayload(null, new List<IOccurrence>() { appt });
                args.Data = payload;
                // Create DragVisual
                var cc = new ContentControl();
                cc.ContentTemplate = Resources.MergedDictionaries[2]["TOLDragVisualTemplate"] as DataTemplate;
                cc.Content = leg;
                args.DragVisual = cc;
                args.AllowedEffects = DragDropEffects.All;
                args.DragVisualOffset = args.RelativeStartPoint;
                args.Handled = true;
    In the schedule view I use ScheduleViewLevel1DragDropBehavior : ScheduleViewDragDropBehavior.
    In the public override bool CanDrop(DragDropState state) the state.DraggedAppointments shows the appointments , so it all works. 

    I will point out here that DragDropState is in fact for this converter an Telerik.Windows.Controls.DragDropState.


    Now I have to enable that the objects from RadListBoxA( Type A ) can also be dropped in another RadListBoxB (type B)

    RadListBoxB already has dragging enabled from other sources , so it uses a SchematicViewListBoxDragDropBehavior : ListBoxDragDropBehavior
    What I noticed is that in the override of CanDrop(DragDropState state) , DragDropState type comes from another namespace: Telerik.Windows.DragDrop.Behaviors.DragDropState

    Whenever I drag something from RadListBoxA to RadListBoxB the state.DraggedItems has no elements. 

    I thought of using the payload.SetData on the ScheduleViewDragDropPayload to attach extra data , but it doesn't implement that , as it seems it's a different kind of payload than the ones used in other documentation , for example this:
    var payload = DragDropPayloadManager.GeneratePayload(null);
    var data = ((FrameworkElement)args.OriginalSource).DataContext;
    payload.SetData("DragData", data);
    args.Data = payload;

    Any suggestions would be much welcome. I'm hoping there is a way of doing it without having to rewrite the whole DragAndDrop between all the other controls that are already working nicely.

    Thank you
  2. Answer
    Nasko avatar
    556 posts

    Posted 07 Nov 2014 Link to this post

    Hi Andrei,

    Thank you for contacting us.

    Based on the provided description we assume that the issue occurs because the type of the items dragged from the first ListBox control does not match the type of the items of  the second ListBox. In order to resolve it you need to create a custom DataConverter for the second ListBox as demonstrated in this article form our help documentation:

    You can also check that sample project in our SDK Repository that demonstrates the described in the article approach.

    Please give it a try and let us know if it worked for you.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. DevCraft banner
  4. Andrei
    Andrei avatar
    7 posts
    Member since:
    Jan 2013

    Posted 09 Dec 2014 in reply to Nasko Link to this post

    Thanks , It worked in the end.
  5. Andrei
    Andrei avatar
    7 posts
    Member since:
    Jan 2013

    Posted 09 Dec 2014 in reply to Nasko Link to this post

Back to Top