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

How to change DragVisual when drag over different control

2 Answers 213 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
rui
Top achievements
Rank 1
rui asked on 21 Dec 2017, 09:10 AM

I drag a item to a control to create an object ,when drag over it,it should display an allowed dragVisual,when drag over another control is should display an Forbidden dragVisual ,the two DragVisual  is create by different Template

it seems AddGiveFeedbackHandler is useful,  in OnGiveFeedback can change the DragVisual  when the target control is Allow, but  I do not know how to get the target control 

how to resolve this

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 25 Dec 2017, 02:54 PM
Hello Rui,

To get the drop target control you can use the OriginalSource property of the event arguments of the drag/drop event which you are using. Note that the property might return a child element instead of the logical element defined in XAML. In this case you can use the ParentOfType<T>() extension method to get the element subscribed to the drag/drop events.

You can also check the Set Drag Visual article. Basically, you can define a DragVisual only on start of the drag operation. However, further in the drag/drop you can update the DragVisual element. I prepared a basic example that shows a sample implementation. 

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
rui
Top achievements
Rank 1
answered on 27 Dec 2017, 08:30 AM
Thank you very much

Inspired by your demo,I find a solution  set dragvisual as a global property when init the drag, and listen to  the allowed target control 's dragover and dragleave event, then change the template of the dragvisual  

it is not a perfect design,  but soled my issue
Tags
DragAndDrop
Asked by
rui
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
rui
Top achievements
Rank 1
Share this question
or