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

How to drop on a RadListBoxItem?

3 Answers 143 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Thorsten
Top achievements
Rank 1
Thorsten asked on 19 Jul 2013, 09:48 AM
Hi,

I'm using the DragDropManager to allow dragging from one RadListBox to another RadListBox. But I need to identify the exact RadListBoxItem on the target list box where the item was dropped onto.

I was hoping to achieve this by using this style for the target list box:
<Style x:Key="DroppableListBoxItem" TargeType="telerik:RadListBoxItem">
   <Setter Property="AllowDrop" Value="true" />
</Style>

And applied this to the list box:
<telerik:RadListBox ItemContainerStyle="{StaticResource DroppableListBoxItem}"
              ItemTemplate="{StaticResource ItemTemplate}"
              ItemsSource="{Binding Path=MyItems}"/>

Note: I did not set AllowDrop=true on the list box itself (I tried it, but I made no difference).

But my DropHandler never returned the list box item, instead I was getting the list box itself.

BTW
Is there a way to highlight the list box item below the the mouse while dragging an item over it?

Thanks,
Thorsten

(I'm using RadControls for WPF Q2 2013)

3 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 24 Jul 2013, 09:11 AM
Hi Thorsten,

Thank you for contacting us.

In order to get on which item the drop was completed you will need to create a custom ListBoxDragDropBehavior and override its Drop method. In that method you can access the InsertIndex from the DragDropState which represents the index in which the dropped item will be added. In the current version of the ListBox control the insert is always done before the item on which the drop was completed and in this case the InsertIndex represents the item on which the drop was completed.

I created and attached a sample project for you with the previously described approach, hope this is helpful. If you have any other questions feel free to write to us again.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Thorsten
Top achievements
Rank 1
answered on 07 Aug 2013, 08:15 AM
Hi Vladi,

thanks for your example and sorry for the late reply, I just returned from a short holiday.

I can see that the Drop()-method of the custom behavior class takes a parameter of type DragDropState, which in turn returns the index of the item where the drop takes place. Using this index and the state.DestinationItemsSource I have access to the target item itself.

BUT: how do I wire this up with my DropHandler for the destination? Or do I need to do my drop logic within the Drop()-method of my behavior class? Or is the DataConverter the right place to do this?

Thanks,
Thorsten

PS
As I do not have SL please use WPF examples ;)
0
Vladi
Telerik team
answered on 08 Aug 2013, 08:12 AM
Hello,

In the current version of RadListBox the DragDropBehavior is responsible for knowing when an item is dragged from the control or drop on it. The DragDropBehavior of a specific ListBox knows only for when items from it are dragged or dropped in it. In order to handle the drop of items on an outside control you will need to handle the Drop on that outside control. In this case when the other control is another ListBox control you will need to create a different DragDropBehavior and handle its Drop method.

I created and attached a WPF sample project that shows the described approach, hope this is helpful. Notice that only the ListBox2 has the custom MyListBoxDragDropBehavior which handled the Drop and DragDropCompleted methods of the ListBox2 control.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
DragAndDrop
Asked by
Thorsten
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Thorsten
Top achievements
Rank 1
Share this question
or