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

RadDragAndDropManager.StartDrag

5 Answers 90 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Travis
Top achievements
Rank 1
Travis asked on 07 Dec 2010, 11:22 PM
Is there an example of manually starting a drag via StartDrag?

Here is what I am attempting to do:
Drag files (ie from Windows Explorer, Desktop, etc) to a Telerik control (in this instance a RadTreeListView).

What I already have working:
Dragging within the RadTreeListView is fully implemented

What I have tried:
Register the DragOver event on the RadTreeListView with this code:

if (!RadDragAndDropManager.IsDragging)
            {
                Collection<object> pPayload = new Collection<object>();
                if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList())
                {
                    foreach (string pFilePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
                    {
                        if (File.Exists(pFilePath))
                        {
                            ITrack pTrack = new MediaTrack();
                            pTrack.IsMasterTrack = true;
                            pTrack.Name = Path.GetFileNameWithoutExtension(pFilePath);
                            pTrack.FileName = pFilePath;
                            pPayload.Add(pTrack);
                        }
                    }
                }
                if (pPayload.Count > 0)
                {
                    RadDragAndDropManager.StartDrag(TrackListTreeListView, pPayload, null);
                }
            }
if (!RadDragAndDropManager.IsDragging)
            {
                Collection<object> pPayload = new Collection<object>();
                if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList())
                {
                    foreach (string pFilePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
                    {
                        if (File.Exists(pFilePath))
                        {
                            ITrack pTrack = new MediaTrack();
                            pTrack.IsMasterTrack = true;
                            pTrack.Name = Path.GetFileNameWithoutExtension(pFilePath);
                            pTrack.FileName = pFilePath;
                            pPayload.Add(pTrack);
                        }
                    }
                }
                if (pPayload.Count > 0)
                {
                    RadDragAndDropManager.StartDrag(TrackListTreeListView, pPayload, null);
                }
            }
   if (!RadDragAndDropManager.IsDragging)
        {
            Collection<object> pPayload = new Collection<object>();
            if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList())
            {
                foreach (string pFilePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
                {
                    if (File.Exists(pFilePath))
                    {
                        pPayload.Add(pFilePath);
                    }
                }
            }
            if (pPayload.Count > 0)
            {
                RadDragAndDropManager.StartDrag(TrackListTreeListView, pPayload, null);
            }
        }

The problem is it never starts the drag!  Is there something I am missing?  I would have thought this would have kick-started the Rad Drag and Drop features, but it doesn't seem to do anything.


Travis
if (!RadDragAndDropManager.IsDragging)
            {
                Collection<object> pPayload = new Collection<object>();
                if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList())
                {
                    foreach (string pFilePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
                    {
                        if (File.Exists(pFilePath))
                        {
                            ITrack pTrack = new MediaTrack();
                            pTrack.IsMasterTrack = true;
                            pTrack.Name = Path.GetFileNameWithoutExtension(pFilePath);
                            pTrack.FileName = pFilePath;
                            pPayload.Add(pTrack);
                        }
                    }
                }
                if (pPayload.Count > 0)
                {
                    RadDragAndDropManager.StartDrag(TrackListTreeListView, pPayload, null);
                }
            }
if (!RadDragAndDropManager.IsDragging)
            {
                Collection<object> pPayload = new Collection<object>();
                if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList())
                {
                    foreach (string pFilePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
                    {
                        if (File.Exists(pFilePath))
                        {
                            ITrack pTrack = new MediaTrack();
                            pTrack.IsMasterTrack = true;
                            pTrack.Name = Path.GetFileNameWithoutExtension(pFilePath);
                            pTrack.FileName = pFilePath;
                            pPayload.Add(pTrack);
                        }
                    }
                }
                if (pPayload.Count > 0)
                {
                    RadDragAndDropManager.StartDrag(TrackListTreeListView, pPayload, null);
                }
            }
if (!RadDragAndDropManager.IsDragging)
            {
                Collection<object> pPayload = new Collection<object>();
                if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList())
                {
                    foreach (string pFilePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
                    {
                        if (File.Exists(pFilePath))
                        {
                            ITrack pTrack = new MediaTrack();
                            pTrack.IsMasterTrack = true;
                            pTrack.Name = Path.GetFileNameWithoutExtension(pFilePath);
                            pTrack.FileName = pFilePath;
                            pPayload.Add(pTrack);
                        }
                    }
                }
                if (pPayload.Count > 0)
                {
                    RadDragAndDropManager.StartDrag(TrackListTreeListView, pPayload, null);
                }
            }
if (!RadDragAndDropManager.IsDragging)
            {
                Collection<object> pPayload = new Collection<object>();
                if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList())
                {
                    foreach (string pFilePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
                    {
                        if (File.Exists(pFilePath))
                        {
                            ITrack pTrack = new MediaTrack();
                            pTrack.IsMasterTrack = true;
                            pTrack.Name = Path.GetFileNameWithoutExtension(pFilePath);
                            pTrack.FileName = pFilePath;
                            pPayload.Add(pTrack);
                        }
                    }
                }
                if (pPayload.Count > 0)
                {
                    RadDragAndDropManager.StartDrag(TrackListTreeListView, pPayload, null);
                }
            }
if (!RadDragAndDropManager.IsDragging)
            {
                Collection<object> pPayload = new Collection<object>();
                if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList())
                {
                    foreach (string pFilePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
                    {
                        if (File.Exists(pFilePath))
                        {
                            ITrack pTrack = new MediaTrack();
                            pTrack.IsMasterTrack = true;
                            pTrack.Name = Path.GetFileNameWithoutExtension(pFilePath);
                            pTrack.FileName = pFilePath;
                            pPayload.Add(pTrack);
                        }
                    }
                }
                if (pPayload.Count > 0)
                {
                    RadDragAndDropManager.StartDrag(TrackListTreeListView, pPayload, null);
                }
            

5 Answers, 1 is accepted

Sort by
0
Travis
Top achievements
Rank 1
answered on 07 Dec 2010, 11:24 PM
Sorry I forgot to mention I have tried this with EnableNativeDrag true and false with no difference.


Travis
0
Accepted
Tsvyatko
Telerik team
answered on 08 Dec 2010, 11:11 AM
Hello Travis,

In this scenario you might want to use OnDropQuery/Info and EnableNativeDrag=true.

Please check the attachment in this blog post -  http://blogs.telerik.com/silverlightteam/posts/10-12-08/drag-from-external-programs-into-you-wpf-applications-using-raddraganddropmanager.aspx  and let me know if this is the desired behavior.

Kind regards,
Tsvyatko
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Travis
Top achievements
Rank 1
answered on 08 Dec 2010, 04:14 PM
That is exactly what I needed.  Thank you!  Maybe this should be cleaned up and added to the "How To" section for the RadDragAndDropManager (under http://www.telerik.com/help/wpf/raddraganddrop-overview.html)?


Travis
0
Travis
Top achievements
Rank 1
answered on 08 Dec 2010, 07:48 PM
Hi Tsvyatko,

I have it all working functionally, but I cannot for the life of me get the DragCue to show up when dragging from outside the program (it works fine when dragging items around the same application).  What I realized is the DragCue is null inside the DropInfo event when dragging items from external programs.  I tried to hook the DragInfo event (as shown in the WPF GridView Reorder Rows sample) to manually create the DragCue item, but this event is never fired for externally dragged items.  As a last attempt, in the DropInfo event I created a DragCue item if it is null, but it is never displayed.

Is there a way to show the DragCue for externally dragged items?


Travis
0
Tsvyatko
Telerik team
answered on 11 Dec 2010, 01:14 PM
Hi Travis,

Unfortunately, this feature is not supported. One of the main reasons are due to the fact that when dragging from external program in ours the events such GiveFeedback and QueryContinueDrag are not raised from OleDragDrop. Thus, in this scenario there is not reliable way to position drag cue according to the current mouse position.

However, I can suggest the following solution:

 - Set RadDragAndDropManager.AllowDrop to true of the root visual of the window.
 - Attach to DropQueryEvent of the root visual of the window and use AdornerLayer to draw the drag cue in it (using e.Options.CurrentDragPoint for current mouse position).


Note that this solution will be able to display drag cue only within the boundaries of the window.

If you have any further questions do not hesitate to contact us.

Best wishes,
Tsvyatko
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
DragAndDrop
Asked by
Travis
Top achievements
Rank 1
Answers by
Travis
Top achievements
Rank 1
Tsvyatko
Telerik team
Share this question
or