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

Drag and Drop in MVVM was broken when I upgraded contols

7 Answers 57 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Michael Hilker
Top achievements
Rank 1
Michael Hilker asked on 23 Mar 2012, 08:30 PM
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?

7 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 26 Mar 2012, 08:53 AM
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 >>
0
Michael Hilker
Top achievements
Rank 1
answered on 26 Mar 2012, 01:48 PM
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.
0
Vlad
Telerik team
answered on 26 Mar 2012, 01:51 PM
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 >>
0
Michael Hilker
Top achievements
Rank 1
answered on 26 Mar 2012, 04:43 PM
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.
0
Vlad
Telerik team
answered on 27 Mar 2012, 06:47 AM
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 >>
0
Michael Hilker
Top achievements
Rank 1
answered on 27 Mar 2012, 01:48 PM
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?
0
Vlad
Telerik team
answered on 27 Mar 2012, 01:49 PM
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 >>
Tags
DragAndDrop
Asked by
Michael Hilker
Top achievements
Rank 1
Answers by
Nick
Telerik team
Michael Hilker
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or