Changing the payload on OnDragOver

9 posts, 1 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 27 Nov 2013 Link to this post

    I'm trying to migrate my legacy drag and drop, but I can't seem to change the text of the cue or payload or draggeditem template when I drag my item over the trashcan image.  I basically just want it to say 'Delete' when it can be dragged.

    For example, I'm dragging an item and when I want to 

    This is my old code:
            private void OnDropInfoTrash(object sender, DragDropEventArgs e)
            {
    ...
    ApplicationInfo payload = e.Options.Payload
    as ApplicationInfo;
     
    ContentControl cue = e.Options.DragCue as ContentControl;
    ContentControl arrow = e.Options.ArrowCue as ContentControl;
    if (e.Options.Status == DragStatus.DropPossible)
    {
        ApplicationInfo api = new ApplicationInfo();
        api.recno = ((ApplicationInfo)cue.Content).recno;
        api.IconPath = "/TimeEntrySL;component/Icons/timeentrySM1.png";
        api.IconText = "Delete";
        cue.Content = api;
    }
    else ...


    This is what I tried in my new code, but this doesn't seem to do anything on the drag over
         DragDropManager.AddDragOverHandler(imgTrash, OnDragOverTrash);

    private
    void OnDragOverTrash(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
    {         
        IDragPayload payload = (IDragPayload)e.Data;
        ApplicationInfo aa = (ApplicationInfo)((IDragPayload)e.Data).GetData("DragData");
            aa.IconText = "Delete";
            e.Effects = DragDropEffects.All;
            payload.SetData("DragData", aa);
            payload.SetData("DropDetails", aa);
            e.Handled = true;
    }

    Is it possible to do this?



  2. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 03 Dec 2013 Link to this post

    Hello,

    In order to achieve your goal, you need to save a reference to the DragVisual in the DragInitialize event and use it later on to modify it as you wish.

    Hope this helps! 


    Regards,
    Yoan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 04 Dec 2013 Link to this post

    I don't seem to get the result that I want, maybe I'm missing something.

    It seems like I can change the text in OnGiveFeedback:
       DragDropManager.AddGiveFeedbackHandler(myListBox, OnGiveFeedback);

    but, I it doesn't fire off an event if I do a feedbackhandler on the trash image.  
         DragDropManager.AddGiveFeedbackHandler(imgTrash, OnGiveFeedbackTrash);
    So I guess this is only on the listbox.  (This doesn't hit my breakpoint when I drag the item over the trash image)


    The dragover handler works, but it won't change my text:

     DragDropManager.AddDragOverHandler(imgTrash, OnDragOverTrash);
            private void OnDragOverTrash(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
            {
            aaCurrent.IconText = "Delete"; //This is global
                dragVisualRef = new ContentControl { Content = aaCurrent, ContentTemplate = this.Resources["ApplicationDragTemplate"] as DataTemplate };

    Maybe I'm missing something?

  5. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 09 Dec 2013 Link to this post

    Hello Dan,

    You can check this online demo on how the ListBoxDragDropBehavior is implemented. The code determining the drop details as dragging over is inside OnDragOver method.

    Regards,
    Yoan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 09 Dec 2013 Link to this post

    I've been trying to use that ondragOver method, but maybe it's over my head.

    aaCurrent.IconText = "Delete";
    var dropDetails = DragDropPayloadManager.GetDataFromObject(e.Data, "DropDetails") as DropIndicationDetails;
    dropDetails.CurrentDraggedOverItem = aaCurrent;
    dropDetails.CurrentDropPosition = Telerik.Windows.Controls.DropPosition.Inside;
     
    e.Handled = true;

    I tried this on the drag over, but it doesn't add the text when I drag over.  It's like I need to do some sort of refresh on the dragvisual.
    my aaCurent item is now global, so the next time I try to drag something it shows "Delete" because I only set the text here.  So I know it's being set.
    Again, maybe this is over my head and I can't spend a few days trying to figure this out from that example.
  7. Nick
    Admin
    Nick avatar
    593 posts

    Posted 13 Dec 2013 Link to this post

    Hi,

    You need to change the Content of your current DragVisual, rather that assigning a new one. The problem is that the Visual cannot be replaced as a whole while dragging. You need to set the Content to the updated value in order to get the changes.

    Hope this helps! 

    Regards,
    Nik
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  8. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 13 Dec 2013 Link to this post

    Sorry it just isn't working for me even if I make every thing global
    aaCurrent.IconText = "Delete";
    ContentControl ccl = (ContentControl)dragVisualRef;
    ccl.Content = aaCurrent;
    ccl.ContentTemplate = this.Resources["ApplicationDragTemplateDel"] as DataTemplate;
    dragVisualRef = ccl;
    I even tried using a converter on the template.  Nothing changes it.

    How do I get my current dragVisual from this besides making it global?
      private void OnDragOverTrash(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
  9. Answer
    Nick
    Admin
    Nick avatar
    593 posts

    Posted 18 Dec 2013 Link to this post

    Hi Dan,

    You shouldn't change the dragVisual reference itself. The change of the Visual in the DragOver handler should look something like: 
    (this.dragVisualRef as ContentControl).Content = new Content

    Hope this makes sense! 

    Regards,
    Nik
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  10. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 18 Dec 2013 Link to this post

    Success!!  Thank you.  It's very easy now actually.

    This below is all that was really needed.
    public MyControl(){  
       InitializeComponent();
     DragDropManager.AddDragInitializeHandler(listBoxTasks, OnDragInitialize);
          DragDropManager.AddGiveFeedbackHandler(listBoxTasks, OnGiveFeedback);
             DragDropManager.AddDragOverHandler(imgTrash, OnDragOverTrash);
        DragDropManager.AddDropHandler(imgTrash, OnTrashDrop);
    }
     
            private void OnDragOverTrash(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
            {
                (this.dragVisualRef as ContentControl).Content = new ApplicationInfo() { IconPath = "/MyApp;component/Icons/TaskImg.png", recno = aaCurrent.recno, IconText = "Delete" };
    }
     
            private void OnDragInitialize(object sender, DragInitializeEventArgs args)
            {
              ...
                args.Data = payload;
                args.DragVisual = new ContentControl { Content = aaCurrent, ContentTemplate = this.Resources["ApplicationDragTemplate"] as DataTemplate };
                dragVisualRef = args.DragVisual;
            ...
            }
            private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs args)
            {
                (this.dragVisualRef as ContentControl).Content = new ApplicationInfo() { IconPath = "/MyApp;component/Icons/TaskImg.png", recno = aaCurrent.recno, IconText = "" };
     
            }
Back to Top
DevCraft banner