Change DragVisual Template in OnGiveFeedback event

1 Answer 67 Views
DragAndDrop
Konstantin
Top achievements
Rank 1
Konstantin asked on 07 Dec 2022, 01:38 PM

Hello!
I want to change DrageVisual Template in OnGiveFeedback event instead of set e.SetCursor(Cursors.Cross); Is it possible?

I am setting DragVisual like this
        

private void OnDragInitialize(object sender, DragInitializeEventArgs e) { e.DragVisual =new ContentControl { Name = "DragVisual", ContentTemplate = this.AssociatedObject.Resources["DraggedItemTemplate"] as DataTemplate, DataContext = items.Count() }; e.DragVisualOffset = e.RelativeStartPoint; e.AllowedEffects = DragDropEffects.All; e.Handled = true; } }


And then set cursor type in this method
        private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs e)
        {            
            if (e.Effects == DragDropEffects.Move)
            {
                e.UseDefaultCursors = false;
                e.SetCursor(Cursors.Arrow);
            }
            else if (e.Effects == DragDropEffects.None)
            {                
                e.UseDefaultCursors = false;
                e.SetCursor(Cursors.Cross);
            }
            else
            {
                e.UseDefaultCursors = true;
            }
            e.Handled = true;
        }

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 12 Dec 2022, 12:47 PM

Hello Konstantin,

The drag visual element in the WPF drag/drop lifecycle can be set only in the start of the drag operation. With DragDropManger, this means the DragInitialize event. However, you can still achieve your requirement. To do so, you can assign an element as the DragVisual on DragInitialize and then, on GiveFeedback or DragOver, replace its Content, Template, ContentTemplate or any other property related to its appearance.

private ContentControl dragVisual;

private void OnDragInitialize(object sender, DragInitializeEventArgs e)
{
   
	this.dragVisual = new ContentControl { Name = "DragVisual" };
	e.DragVisual = this.dragVisual;
	// other code here
}

private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs e)
{            
	// other code here
	this.dragVisual.Content = newContent;
}

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Konstantin
Top achievements
Rank 1
commented on 15 Dec 2022, 11:21 AM

Hello, Martin!
It works, thank you!
Tags
DragAndDrop
Asked by
Konstantin
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or