Drag and Drop in MVVM was broken when I upgraded contols

8 posts, 0 answers
  1. Michael Hilker
    Michael Hilker avatar
    5 posts
    Member since:
    Feb 2010

    Posted 23 Mar 2012 Link to this post

    I have an MVVM project with Several RadGridViews inside of a RadTabControl and a RadTabControl containing Listboxes which are defined in an datatemplate.
    I had Drag and Drop working fine when using version 2011.2.712.40
    However, when I upgraded to the current release the drag and drop functionality does not work.

    I found the following thread (see below) and downloaded the last example contained within, sure enough it has the same problem...
    if you run the example with the version contained in the lib folder Drag and Drop works fine, then if you upgrade the controls to the current  version, Drag and Drop no longer functions.

    http://www.telerik.com/community/forums/wpf/draganddrop/drag-drop-related-problem-in-mvvm.aspx

    What has changed that would impact Drag and Drop, and how can I correct it?
  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 26 Mar 2012 Link to this post

    Hi Michael,

    The reason for this is that there were some changes made in the RadTreeView, related to it's internal drag & drop behavior. You will have to subscribe the the ItemCreated event and set the Allow Drag property there. 

    protected override void OnAttached()
            {
                base.OnAttached();
     
                RadDragAndDropManager.AddDragQueryHandler(this.AssociatedObject, OnDragQuery);
                RadDragAndDropManager.AddDragInfoHandler(this.AssociatedObject, OnDragInfo);
     
                RadDragAndDropManager.AddDropQueryHandler(this.AssociatedObject, OnDropQuery);
                RadDragAndDropManager.AddDropInfoHandler(this.AssociatedObject, OnDropInfo);
     
                if (this.AssociatedObject is RadTreeView)
                {
                    (this.AssociatedObject as RadTreeView).ItemPrepared += new EventHandler<RadTreeViewItemPreparedEventArgs>(CommandDragDropBehavior_ItemPrepared);
                }
            }
     
            void CommandDragDropBehavior_ItemPrepared(object sender, RadTreeViewItemPreparedEventArgs e)
            {
                try
                {
                    RadDragAndDropManager.SetAllowDrag(e.PreparedItem, true);
                    RadDragAndDropManager.SetAllowDrop(e.PreparedItem, true);
                }
                catch
                {
                }
            }

    Hope this helps!  Regards,
    Nik
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Michael Hilker
    Michael Hilker avatar
    5 posts
    Member since:
    Feb 2010

    Posted 26 Mar 2012 Link to this post

    Is there an example that includes this for MVVM?  Or could you update the example in the attached thread so I can be sure I'm implementing it correctly.
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 26 Mar 2012 Link to this post

    Hello,

     We believe that the example is already MVVM ready. Have you tried our code? Do you see anything wrong?

    Kind regards,
    Vlad
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Michael Hilker
    Michael Hilker avatar
    5 posts
    Member since:
    Feb 2010

    Posted 26 Mar 2012 Link to this post

    OK that fixes the issue if the control is a RadTreeView as in the example.  However, I'm using RadListBox and RadGridView, how do I address that.  I applied your suggestion to the example and indeed that fixed the problem, I then changed the RadTreeView to a RadListBox and again it does not allow me to Drag and Drop.
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 27 Mar 2012 Link to this post

    Hi,

    You should change the code when you use different components - as you can see there is a cast in the code for RadTreeView. 

    Regards,
    Vlad
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  8. Michael Hilker
    Michael Hilker avatar
    5 posts
    Member since:
    Feb 2010

    Posted 27 Mar 2012 Link to this post

    Is this the line you're refering to?
    (this.AssociatedObject as RadTreeView).ItemPrepared += new EventHandler<RadTreeViewItemPreparedEventArgs>(CommandDragDropBehavior_ItemPrepared);                 

    It appears as though neither RadGridView Nor RadListBox have the ItemPrepared Event.  Am I missing something?
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 27 Mar 2012 Link to this post

    Hello,

    This was just an example. The idea is that you have you change the code to fit your scenario.

    Greetings,
    Vlad
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
UI for WPF is Visual Studio 2017 Ready