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

Drop failing after enabling native drag

2 Answers 130 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Jinyan
Top achievements
Rank 1
Jinyan asked on 07 Aug 2012, 10:26 PM
Hi all,

I chose to use EnableNativeDrag to get around another bug I was having with the drag/drop (was giving me errors regarding my layout not wrapped in adorners layer, and someone suggested to use native drag). However, my OnDropInfo code, which was working previously, is now not executing the block when drop status is DropComplete. 

More info:

I did RadDragAndDropManager.EnableNativeDrag = true in my drag source. The drag source is a RadTreeView and drop target is a RadChart.

Drag code:

private void OnDragQueryHandler(object sender, DragDropQueryEventArgs e)
{
    if (e.Options.Status == DragStatus.DragQuery)
    {
        RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;
        ContentControl cue = new ContentControl();
        cue.ContentTemplate = this.Resources["ApplicationDragTemplate"] as DataTemplate;
 
        cue.Content = new TextBlock()
        {
            Padding = new Thickness(5),
            Background = new SolidColorBrush(Colors.LightBlue),
            FontSize = 12
        };
 
        if (item.Item is CustomItem)
        {
            // do stuff
        }
        else
        {
            e.QueryResult = false;
            return;
        }
 
        e.Options.DragCue = cue;
    }
    e.QueryResult = true;
}
 
private void OnDragInfoHandler(object sender, DragDropEventArgs e)
{
    if (e.Options.Status == DragStatus.DragComplete)
    {
        // do stuff
    }
}

And drop code:

private void OnDropQueryHandler(object sender, DragDropQueryEventArgs e)
{
    var payload = e.Options.Payload;
 
    e.QueryResult = payload is CustomItem;
}
 
private void OnDropInfoHandler(object sender, DragDropEventArgs e)
{
    if (e.Options.Status == DragStatus.DropPossible)
    {
        UI_RadChart.BorderBrush = WPConstants.DRAG_BRUSH;
    }
    else
    {
        UI_RadChart.BorderBrush = null;
    }
 
    if (e.Options.Status == DragStatus.DropComplete)
    {
        // DO STUFF, NOT REACHING HERE
    }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosen Vladimirov
Telerik team
answered on 08 Aug 2012, 02:30 PM
Hello,

I would like to recommend you to use the newer DragDropManager instead of RadDragAndDropManager. It has several changes and upgrades in it which I think will be very useful in your case.
To illustrate how to use the DragDropManager, I'm sending you two examples. The first one (DragDropManager_WPF_574181) is very simple and it is showing the events you'll have to use for your case. The second one (DragDropManager_Example) is fully functional and it will provide you with a working project in which you'll be able to drag and drop items between two ListBoxes. This second example is in fact the one you'll find explained in our online help here. I strongly recommend you to read this article which is describing the differences between RadDragAndDropManager and DragDropManager.

Please check the attached projects and the articles in our online help and don't hesitate to contact us if you face any problems with RadControls.

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Jinyan
Top achievements
Rank 1
answered on 08 Aug 2012, 06:00 PM
Hi Rosen,

Thanks for the response! I am now using DragDropManager instead of RadDragAndDropManager. However, I can't seem to get the drop working. My OnDragEnter and OnDragLeave callbacks for the drop targets are working fine, but it never enters the OnDrop or OnDragCompleted callbacks for the drop target. Any ideas why? I have AllowDrop set to true on the target.

Edit: Never mind I am now hitting OnDragCompleted if I attach it to the source of the drag. However, my OnDrop is still not getting hit for some reason.

More information:
Drag source - RadTreeView
Drop target - RadChart
DragVisual - TextBlock (not sure if it matters)

Source.DragInitialize working
Source.DragCompleted working
Target.DragEnter working
Target.DragLeave working
Target.Drop not working
Target.PreviewDrop not working

When I am trying to debug it, the program goes straight to DragCompleted handler when I drop the textblock, which makes it seem that Drop event is being caught somewhere. But shouldn't PreviewDrop capture that?

Edit2: It seems that this is a problem with the Visual Studio Isolated Shell since I am using it to host my application. I think that the shell is capturing my drop events, thus preventing it from propagating down to my control. Reasons being that if I drag/drop fast enough, the drop event will eventually hit my Drop handler, presumably at times when the shell cannot handle the drop events fast enough. Thanks for the help, I'll try asking the VS Extensibility forum regarding this issue.
Tags
DragAndDrop
Asked by
Jinyan
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Jinyan
Top achievements
Rank 1
Share this question
or