This question is locked. New answers and comments are not allowed.
I have implemented the multiple selection on drag and drop referring to your help site.
But there is something odd.
Items can be selected and dragged in multiple but they are not dropped.
The dropinfo event is not fired ever. And I don't know where the problem is in my code.
Here is my code.
<XAML>
<C#>
Thanks in advance.
But there is something odd.
Items can be selected and dragged in multiple but they are not dropped.
The dropinfo event is not fired ever. And I don't know where the problem is in my code.
Here is my code.
<XAML>
<UserControl x:Class="SilverlightApplication1.MainPage" xmlns:local="clr-namespace:SilverlightApplication1" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <Grid.Resources> <Style TargetType="ListBoxItem"> <Setter Property="telerik:RadDragAndDropManager.AllowDrop" Value="True"/> <Setter Property="telerik:RadDragAndDropManager.AllowDrag" Value="True"/> </Style> <Style TargetType="local:ExtendedListBoxItem"> <Setter Property="telerik:RadDragAndDropManager.AllowDrag" Value="True"/> <Setter Property="telerik:RadDragAndDropManager.AutoDrag" Value="True"/> </Style> </Grid.Resources> <local:ExtendedListBox x:Name="SourceBox" ItemsSource="{Binding Data}" SelectionMode="Extended" ClickOnSelectedItemAction="KeepSelectionIfItemSelected"> <local:ExtendedListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding UserName}"/> </DataTemplate> </local:ExtendedListBox.ItemTemplate> </local:ExtendedListBox> <!-- <local:ExtendedListBox x:Name="DestinationBox" ItemsSource="{Binding Data}" SelectionMode="Extended" Grid.Row="1"> <local:ExtendedListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding UserName}"/> </DataTemplate> </local:ExtendedListBox.ItemTemplate> </local:ExtendedListBox> --> <ListBox x:Name="DestinationBox" ItemsSource="{Binding Data}" SelectionMode="Extended" Grid.Row="1"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding UserName}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid></UserControl><C#>
using System.Linq;using System.Windows;using System.Windows.Controls;using System.Windows.Input;using Telerik.Windows.Controls.DragDrop;using Telerik.Windows.Controls.GridView;using System.Collections;using Telerik.Windows.Controls;using System.Collections.ObjectModel;using System;using System.ComponentModel;using System.Collections.Generic;using System.Windows.Media;namespace SilverlightApplication1{ public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); RadDragAndDropManager.ExecutionMode = DragExecutionMode.Legacy; RadDragAndDropManager.Initialize(); //this.DataContext = new MainViewModel(); //DestinationBox.DataContext = new MainViewModel(); SourceBox.ItemsSource = Data.GetItems(); //DestinationBox.ItemsSource = Data.GetItems(); RadDragAndDropManager.AddDragInfoHandler(this.SourceBox, SourceBox_DragInfo); RadDragAndDropManager.AddDropInfoHandler(this.DestinationBox, DestinationBox_DropInfo); } private void SourceBox_DragInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e) { if (!(e.Options.DragCue is TreeListViewDragCue)) { var draggedItems = ((System.Windows.Controls.ListBox)sender).SelectedItems.OfType<object>().ToList(); var dragCue = new TreeListViewDragCue() { ItemsSource = draggedItems }; dragCue.DisplayMemberPath = "UserName"; dragCue.DragTooltipVisibility = Visibility.Collapsed; e.Options.DragCue = dragCue; e.Options.Payload = draggedItems; } if (e.Options.Status == DragStatus.DragComplete && e.Options.Payload is IList) { var itemsSource = ((System.Windows.Controls.ListBox)sender).ItemsSource as IList; foreach (var item in ((IList)e.Options.Payload)) { itemsSource.Remove(item); } } } private void DestinationBox_DropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e) { if (e.Options.Status == DragStatus.DropComplete && e.Options.Payload is IList) { var itemsSource = ((System.Windows.Controls.ListBox)sender).ItemsSource as IList; foreach (var item in ((IList)e.Options.Payload)) { itemsSource.Add(item); } } } } public class ExtendedListBox : System.Windows.Controls.ListBox { public ClickAction ClickOnSelectedItemAction { get { return (ClickAction)GetValue(ClickOnSelectedItemActionProperty); } set { SetValue(ClickOnSelectedItemActionProperty, value); } } // Using a DependencyProperty as the backing store for ClickOnSelectedItemAction. This enables animation, styling, binding, etc... public static readonly DependencyProperty ClickOnSelectedItemActionProperty = DependencyProperty.Register("ClickOnSelectedItemAction", typeof(ClickAction), typeof(ExtendedListBox), new PropertyMetadata(ClickAction.OverrideSelection)); protected override DependencyObject GetContainerForItemOverride() { //return base.GetContainerForItemOverride(); ExtendedListBoxItem item = new ExtendedListBoxItem(); item.ParentListBox = this; if (this.ItemContainerStyle != null) { item.Style = this.ItemContainerStyle; } return item; } } public enum ClickAction { KeepSelectionIfItemSelected, OverrideSelection } public class ExtendedListBoxItem : System.Windows.Controls.ListBoxItem { public ExtendedListBox ParentListBox { get; set; } protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (this.ParentListBox != null && this.ParentListBox.ClickOnSelectedItemAction == ClickAction.KeepSelectionIfItemSelected && this.IsSelected) { return; } base.OnMouseLeftButtonDown(e); } } public class Data { private String objName; public String UserName { get { return this.objName; } set { if (this.UserName == value) return; this.objName = value; OnPropertyChanged("UserName"); } } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string info) { PropertyChangedEventHandler temp = this.PropertyChanged; if (temp != null) temp(this, new PropertyChangedEventArgs(info)); } public static IList<object> GetItems() { ObservableCollection<object> result = new ObservableCollection<object>(); for (int i = 0; i < 10; i++) { result.Add(new Data { UserName = "UserName : " + i }); } return result; } }}Thanks in advance.