简体   繁体   中英

Silverlight ListBox Drag and Drop

I'm trying to implement drag and drop functionality between two telerik list boxes. I've done it using the following code

Listbox 1 :

<telerik:RadListBox x:Name="name1" SelectionMode="Multiple" >
    <telerik:RadListBox.DragVisualProvider> 
        <telerik:ScreenshotDragVisualProvider />
    </telerik:RadListBox.DragVisualProvider>
    <telerik:RadListBox.DragDropBehavior>
        <telerik:ListBoxDragDropBehavior />
    </telerik:RadListBox.DragDropBehavior>
</telerik:RadListBox>

Listbox 2 :

<telerik:RadListBox x:Name="name2" AllowDrop="True">
   <telerik:RadListBox.DragDropBehavior>
       <telerik:ListBoxDragDropBehavior />
   </telerik:RadListBox.DragDropBehavior>
</telerik:RadListBox>

Added this Style :

<Style TargetType="telerik:RadListBoxItem" >
    <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
</Style>

It works perfectly but i don't want the element to be removed from the source list box when it is being dragged to the other list box

From telerik help about a treeview (same for others):

If you want after the drag and drop operation is completed to remove the item from the tree view then do not handle the PreviewDragEnded for the tree view.

so, all u need is:

<telerik:RadTreeView x:Name="radTreeView" Margin="8,8,20,8"
    PreviewDragEnded="radTreeView_PreviewDragEnded"
    ItemsSource="{Binding Source={StaticResource DataSource}, Path=LeaguesDataSource}"
    ItemTemplate="{StaticResource League}"
    IsDragDropEnabled="True"
    IsDragTooltipEnabled="False"/>

code-behind:

private void radTreeView_PreviewDragEnded( object sender, RadTreeViewDragEndedEventArgs e )
{
   e.Handled = true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM