How to change DragVisual when drag over different control

3 posts, 1 answers
  1. rui
    rui avatar
    78 posts
    Member since:
    May 2014

    Posted 21 Dec 2017 Link to this post

    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. Answer
    Martin Ivanov
    Admin
    Martin Ivanov avatar
    1882 posts

    Posted 25 Dec 2017 Link to this post

    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.
  3. rui
    rui avatar
    78 posts
    Member since:
    May 2014

    Posted 27 Dec 2017 Link to this post

    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
Back to Top