Drop not called

4 posts, 0 answers
  1. Selva Saravana
    Selva Saravana avatar
    4 posts
    Member since:
    Aug 2013

    Posted 12 Nov 2013 Link to this post

    Hi ,

    In my application, i have two radlistboxes. When i drag an item from one to another, the item gets added correctly.
    But   "DragOver"  and  "Drop"  event is never called. What i should do to invoke the drop.

    Thanks in advance,
    Selva
  2. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 14 Nov 2013 Link to this post

    Hi Selva,

    You can add event handlers as described in this help article. Please check the following code snippet for reference:

    DragDropManager.AddDropHandler(ApplicationList, OnElementDragOver);
    DragDropManager.AddDropHandler(MyAppList, OnElementDragOver);
      
    private void OnElementDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
            {
            }

    For your convenience, I have attached a sample project where you can see that the DragOver event is firing.

    Regards,
    Yoan
    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. Brian
    Brian avatar
    1 posts
    Member since:
    Nov 2013

    Posted 18 Nov 2013 Link to this post

    I am also not able to get the Drop event to fire.  I have looked at the demo projects and the sample project attached to this thread, but can't seem to get my sample project to work correctly.  If you could take a quick look and see what is wrong I would appreciate it.

    My company is considering purchasing some Telerik licenses so that we can replace some of our current drag/drop functionality with the Telerik controls and so far they are great, but this is the first roadblock I've come across.

    Thanks in advance for the help!

    <Window x:Class="WpfApplication1.MainWindow"
            xmlns:local="clr-namespace:WpfApplication1"
            Title="MainWindow" Height="800" Width="600" x:Name="DDWindow">
        
       <Window.DataContext>
          <local:MonthViewModel />
       </Window.DataContext>
       <Window.Resources>
          <DataTemplate x:Key="ListBoxItemTemplate">
             <Grid>
                <Grid.ColumnDefinitions>
                   <ColumnDefinition Width="Auto" />
                   <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                 
                <Image Source="calendar-small.png" Grid.Column="0" HorizontalAlignment="Left" />
                <TextBlock Text="{Binding MonthName}" Grid.Column="1" HorizontalAlignment="Left" />
             </Grid>
          </DataTemplate>
      
          <Style TargetType="telerik:RadListBoxItem">
             <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
             <Setter Property="telerik:DragDropManager.TouchDragTrigger" Value="TapAndHold"/>
          </Style>
          <Style TargetType="telerik:RadListBox">
             <Setter Property="BorderThickness" Value="2" />
          </Style>
       </Window.Resources>
        
        <Grid x:Name="LayoutRoot">
           <Grid.RowDefinitions>
             <RowDefinition Height="*" />
             <RowDefinition Height="*" />
          </Grid.RowDefinitions>
            
          <telerik:RadListBox Grid.Row="0" x:Name="MonthListBox1" Margin="10" ItemsSource="{Binding MonthList}" ItemTemplate="{StaticResource ListBoxItemTemplate}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AllowDrop="True">
             <telerik:RadListBox.DragDropBehavior>
                <telerik:ListBoxDragDropBehavior AllowReorder="True" telerik:DragDropManager.TouchDragTrigger="TapAndHold" />
             </telerik:RadListBox.DragDropBehavior>
             <telerik:RadListBox.DragVisualProvider>
                <telerik:ScreenshotDragVisualProvider />
             </telerik:RadListBox.DragVisualProvider>
          </telerik:RadListBox>
      
          <telerik:RadListBox Grid.Row="1" x:Name="MonthListBox2" Margin="10" ItemsSource="{Binding GroupB}" ItemTemplate="{StaticResource ListBoxItemTemplate}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AllowDrop="True">
             <telerik:RadListBox.DragDropBehavior>
                <telerik:ListBoxDragDropBehavior AllowReorder="True" telerik:DragDropManager.TouchDragTrigger="TapAndHold" />
             </telerik:RadListBox.DragDropBehavior>
             <telerik:RadListBox.DragVisualProvider>
                <telerik:ScreenshotDragVisualProvider />
             </telerik:RadListBox.DragVisualProvider>
              
          </telerik:RadListBox>
              
       </Grid>
    </Window>
    namespace WpfApplication1
    {
       public class Month
       {
          private string monthName;
          private int monthNumber;
     
          public string MonthName
          {
             get;
             set;
          }
     
          public int MonthNumber
          {
             get;
             set;
          }
       }
    }
    using System.Collections.ObjectModel;
    using Telerik.Windows.Controls;
     
    namespace WpfApplication1
    {
       public class MonthViewModel : ViewModelBase
       {
          ObservableCollection<Month> monthList = new ObservableCollection<Month>();
     
          public MonthViewModel()
          {
             this.GroupA = new ObservableCollection<Month>();
             this.GroupB = new ObservableCollection<Month>();
          }
     
          public ObservableCollection<Month> MonthList
          {
             get
             {
                this.monthList.Add(new Month { MonthName = "January", MonthNumber = 1 });
                this.monthList.Add(new Month { MonthName = "February", MonthNumber = 2 });
                this.monthList.Add(new Month { MonthName = "March", MonthNumber = 3 });
                this.monthList.Add(new Month { MonthName = "April", MonthNumber = 4 });
                this.monthList.Add(new Month { MonthName = "May", MonthNumber = 5 });
                this.monthList.Add(new Month { MonthName = "June", MonthNumber = 6 });
                this.monthList.Add(new Month { MonthName = "July", MonthNumber = 7 });
                this.monthList.Add(new Month { MonthName = "August", MonthNumber = 8 });
                this.monthList.Add(new Month { MonthName = "September", MonthNumber = 9 });
                this.monthList.Add(new Month { MonthName = "October", MonthNumber = 10 });
                this.monthList.Add(new Month { MonthName = "November", MonthNumber = 11 });
                this.monthList.Add(new Month { MonthName = "December", MonthNumber = 12 });
     
                return this.monthList;
             }
          }
     
          public ObservableCollection<Month> GroupA
          {
             get;
             set;
          }
     
          public ObservableCollection<Month> GroupB
          {
             get;
             set;
          }
       }
    }

    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using Telerik.Windows.DragDrop;
     
    namespace WpfApplication1
    {
       /// <summary>
       /// Interaction logic for MainWindow.xaml
       /// </summary>
       public partial class MainWindow : Window
       {
          public MainWindow()
          {
             InitializeComponent();
     
             DragDropManager.AddDragInitializeHandler(MonthListBox1, OnDragInitialize);
             DragDropManager.AddGiveFeedbackHandler(MonthListBox1, OnGiveFeedback);
             DragDropManager.AddDragDropCompletedHandler(MonthListBox1, OnDragCompleted);
             DragDropManager.AddDropHandler(MonthListBox1, OnDrop);
     
     
             DragDropManager.AddDragInitializeHandler(MonthListBox2, OnDragInitialize);
             DragDropManager.AddGiveFeedbackHandler(MonthListBox2, OnGiveFeedback);
             DragDropManager.AddDragDropCompletedHandler(MonthListBox2, OnDragCompleted);
             DragDropManager.AddDropHandler(MonthListBox2, OnDrop);
          }
     
          private void OnDragInitialize(object sender, DragInitializeEventArgs args)
          {
             args.AllowedEffects = DragDropEffects.Move;
             var payload = DragDropPayloadManager.GeneratePayload(null);
             payload.SetData("DragData", ((FrameworkElement)args.OriginalSource).DataContext);
             args.Data = payload;
             args.DragVisual = new ContentControl {Content = args.Data, ContentTemplate = DDWindow.Resources["ListBoxItemTemplate"] as DataTemplate};
          }
     
          private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs e)
          {
             e.SetCursor(Cursors.Arrow);
             e.Handled = true;
          }
     
          public void OnDragCompleted(object sender, Telerik.Windows.DragDrop.DragDropCompletedEventArgs e)
          {
             int x = 0;
          }
     
          private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
          {
             int x = 0;
          }
       }
    }
  5. Nick
    Admin
    Nick avatar
    593 posts

    Posted 19 Nov 2013 Link to this post

    Hello Brian,

    As mentioned before, in order to get the DropEvent called, you need to have effects that are different from None. You can check the effects in the DragOver event and change them if needed.

    Hope this makes sense! 

    Regards,
    Nik
    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