简体   繁体   English

Silverlight ListBox拖放

[英]Silverlight ListBox Drag and Drop

I'm trying to implement drag and drop functionality between two telerik list boxes. 我正在尝试在两个telerik列表框之间实现拖放功能。 I've done it using the following code 我已经使用以下代码完成了

Listbox 1 : 清单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 : 清单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): 从telerik帮助中获取关于树视图的信息(与其他视图相同):

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. 如果要在完成拖放操作后从树视图中删除该项目,请不要处理树视图的PreviewDragEnded。

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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