RadDragAndDropManager.StartDrag

6 posts, 1 answers
  1. Travis
    Travis avatar
    8 posts
    Member since:
    Nov 2010

    Posted 07 Dec 2010 Link to this post

    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);
                    }
                
  2. Travis
    Travis avatar
    8 posts
    Member since:
    Nov 2010

    Posted 07 Dec 2010 Link to this post

    Sorry I forgot to mention I have tried this with EnableNativeDrag true and false with no difference.


    Travis
  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 08 Dec 2010 Link to this post

    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
  5. Travis
    Travis avatar
    8 posts
    Member since:
    Nov 2010

    Posted 08 Dec 2010 Link to this post

    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
  6. Travis
    Travis avatar
    8 posts
    Member since:
    Nov 2010

    Posted 08 Dec 2010 Link to this post

    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
  7. Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 11 Dec 2010 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready