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

Changing the payload on OnDragOver

8 Answers 46 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
danparker276
Top achievements
Rank 2
danparker276 asked on 28 Nov 2013, 12:11 AM
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?



8 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 03 Dec 2013, 08:02 AM
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 >>
0
danparker276
Top achievements
Rank 2
answered on 04 Dec 2013, 10:30 PM
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?

0
Yoan
Telerik team
answered on 09 Dec 2013, 04:37 PM
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 >>
0
danparker276
Top achievements
Rank 2
answered on 09 Dec 2013, 08:49 PM
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.
0
Nick
Telerik team
answered on 13 Dec 2013, 09:58 AM
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 >>
0
danparker276
Top achievements
Rank 2
answered on 13 Dec 2013, 07:10 PM
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)
0
Accepted
Nick
Telerik team
answered on 18 Dec 2013, 12:11 PM
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 >>
0
danparker276
Top achievements
Rank 2
answered on 18 Dec 2013, 05:51 PM
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 = "" };
 
        }
Tags
DragAndDrop
Asked by
danparker276
Top achievements
Rank 2
Answers by
Yoan
Telerik team
danparker276
Top achievements
Rank 2
Nick
Telerik team
Share this question
or