DragDropManager events and Prism InvokeCommandAction

5 posts, 0 answers
  1. Dmitry
    Dmitry avatar
    20 posts
    Member since:
    Apr 2011

    Posted 02 Jun 2014 Link to this post

    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?
  2. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 04 Jun 2014 Link to this post

    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.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Dmitry
    Dmitry avatar
    20 posts
    Member since:
    Apr 2011

    Posted 04 Jun 2014 in reply to Kalin Link to this post

    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.



  5. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 04 Jun 2014 Link to this post

    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.
     
  6. Dmitry
    Dmitry avatar
    20 posts
    Member since:
    Apr 2011

    Posted 04 Jun 2014 in reply to Kalin Link to this post

    Yes, this helps. Thank you!
Back to Top
UI for WPF is Visual Studio 2017 Ready