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

DragDropManager events and Prism InvokeCommandAction

4 Answers 167 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Dmitry
Top achievements
Rank 1
Dmitry asked on 02 Jun 2014, 11:50 AM
Hello!

I need to process PreviewDrop  event from telerik's DragDropManager, and I am using Prism 5.0 in my WPF application.
I tried to search documentation and forums, but I was not able to find examples of how can I subscribe my command from ViewModel with the DragDropManager event PreviewDrop to be able to check if operation can be done, or I need to cancel the drop.

Can anyone help me with this?

4 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 04 Jun 2014, 10:38 AM
Hello Dmitry,

Thank you for contacting us.

The DragDropManager is designed to work with UI elements in the UI thread and using it in the ViewModel would break MVVM pattern - that is why such an implementation is not recommend. However what I can suggest you would be to check the Getting Started article from our online help documentation which demonstrates the recommended approach for using the DragDropManager.

Hope this helps.


Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Dmitry
Top achievements
Rank 1
answered on 04 Jun 2014, 10:48 AM
Hello Kalin,

I am sorry, but I can not understand how using DragDropManager wuold break MVVM pattern. When DragDropManager fires an event - it does that in UI thread. Like any other UI element - their events are fired on UI thread. Am I right? Then using EventToCommand binding (or similar thing in Prism is called InvokeActionCommand) would pass this event into ViewModel while still in UI thread.

What I need - is a possibility to attach EventToCommand to the DragDropManager events. I successfully did this with RadTreeView events like PreviewSelectionChanged totally in a manner of MVVM pattern. Why this would break with DDM?

Ok, I can reformulate my question to this - how can I subscribe to DragDropManager events in XAML?

And getting started you are reffering to - has nothing to do with MVVM, and subscription is happening code-behind with data created also at the code-behind.

Thanks in advance.



0
Kalin
Telerik team
answered on 04 Jun 2014, 03:37 PM
Hello Dmitry,

The events of the DragDropManager are not public and they cannot be used with the EventToCommandBehavior in XAML. What I've meant in the previous post was that you will need to pass an instance of the UI element to the ViewModel in order to be able to handle the methods there and this would break the MVVM pattern. Other solution would be to use an attached behavior which hooks the DragDropManager methods to the desired UI element. Inside of the handlers you can get the DataContext of the UI element and execute the needed logic in order to prevent or not the drop operation. For your convenience I have prepared a sample project which demonstrates the exact approach using ListBoxes, please check it and let me know if it helps.

I hope this work for your scenario.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Dmitry
Top achievements
Rank 1
answered on 04 Jun 2014, 04:11 PM
Yes, this helps. Thank you!
Tags
DragAndDrop
Asked by
Dmitry
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Dmitry
Top achievements
Rank 1
Share this question
or