Double-fired OnDrop for listbox inside RadTileView

1 posts, 0 answers
  1. Wenrong
    Wenrong avatar
    36 posts
    Member since:
    May 2012

    Posted 05 Jun 2012 Link to this post

    When the list box lives inside a RadTileView, the OnDrop event will get fired twice with the same parameters.
    <telerik:RadTileView>
        <telerik:RadTileViewItem>
     
            <Grid x:Name="LayoutRoot" Background="White">
                <Grid.Resources>
                    <Style TargetType="ListViewItem">
                        <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True"></Setter>
                    </Style>
                    <DataTemplate x:Key="ApplicationTemplate">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Margin="5" Text="{Binding Name}" VerticalAlignment="Center"></TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </Grid.Resources>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <ListView x:Name="ApplicationList" ItemTemplate="{StaticResource ApplicationTemplate}" AllowDrop="True"/>
                <ListView x:Name="MyAppList" Background="Gray" Grid.Column="1" 
                ItemTemplate="{StaticResource ApplicationTemplate}" AllowDrop="True"/>
            </Grid>
        </telerik:RadTileViewItem>
    </telerik:RadTileView>


    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            ObservableCollection<Item> items = new ObservableCollection<Item>();
            for (int i = 1; i <= 10; i++)
                items.Add(new Item() { Name = string.Format("item {0}", i) });
            ApplicationList.ItemsSource = items;
            MyAppList.ItemsSource = new ObservableCollection<Item>();
     
            DragDropManager.AddDragInitializeHandler(ApplicationList, OnDragInitialize);
            DragDropManager.AddDragInitializeHandler(MyAppList, OnDragInitialize);
            DragDropManager.AddGiveFeedbackHandler(ApplicationList, OnGiveFeedback);
            DragDropManager.AddGiveFeedbackHandler(MyAppList, OnGiveFeedback);
            DragDropManager.AddDragDropCompletedHandler(ApplicationList, OnDragCompleted);
            DragDropManager.AddDragDropCompletedHandler(MyAppList, OnDragCompleted);
            DragDropManager.AddDropHandler(ApplicationList, OnDrop);
            DragDropManager.AddDropHandler(MyAppList, OnDrop);
        }
     
        private void OnDragInitialize(object sender, DragInitializeEventArgs args)
        {
            args.AllowedEffects = DragDropEffects.Move;
            //args.AllowedEffects = DragDropEffects.All;
            args.Data = ((FrameworkElement)args.OriginalSource).DataContext;
            args.DragVisual = new ContentControl { Content = args.Data, ContentTemplate = LayoutRoot.Resources["ApplicationTemplate"] as DataTemplate };
        }
     
        private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs args)
        {
            System.Diagnostics.Trace.WriteLine(string.Format("{0} - OnGiveFeedback sender={1}", DateTime.Now, sender));
            args.SetCursor(Cursors.Arrow);
            args.Handled = true;
        }
     
        private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs args)
        {
            System.Diagnostics.Trace.WriteLine(string.Format("{0} - OnDrop sender={1}", DateTime.Now, sender));
            ((IList)(sender as ListBox).ItemsSource).Add(((DataObject)args.Data).GetData(typeof(Item)));
        }
     
        public void OnDragCompleted(object sender, Telerik.Windows.DragDrop.DragDropCompletedEventArgs args)
        {
            System.Diagnostics.Trace.WriteLine(string.Format("{0} - OnDragCompleted sender={1}", DateTime.Now, sender));
            ((IList)(sender as ListBox).ItemsSource).Remove(args.Data);
        }
    }
     
    public class Item
    {
        public string Name { get; set; }
    }

Back to Top