How to drop on a RadListBoxItem?

4 posts, 0 answers
  1. Thorsten
    Thorsten avatar
    8 posts
    Member since:
    Oct 2010

    Posted 19 Jul 2013 Link to this post

    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)
  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 24 Jul 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Thorsten
    Thorsten avatar
    8 posts
    Member since:
    Oct 2010

    Posted 07 Aug 2013 Link to this post

    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 ;)
  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 08 Aug 2013 Link to this post

    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 >>
Back to Top