Drag & Drop not working after Upgrade

12 posts, 1 answers
  1. Dušan
    Dušan avatar
    8 posts
    Member since:
    Oct 2012

    Posted 23 Aug 2013 Link to this post

    Greetings,

    I have recently upgraded to the newest RAD Controls for WPF and discovered problem with Drag & Drop. It is not working after upgrade.
    I have made small project to verify that problem is not in our code and when I use dlls of version "2012.3.1129.40" it is working without problem. When I use dlls of version 2013.2.0611.40 it is not working. Could you help me out?

    In attachement I sent a small WPF project.  You can see that in xaml I aneble dragging on each item in RadTreeView and in the code you can see that I add handlers for Drag & Drop operations. When drop occurs I add info about it to the listbox. For old dlls it works but for new ones it does not.

    Xaml:
    <Window x:Class="TelerikWpfApplication.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <Grid>
    <telerik:RadTreeView Height="250" HorizontalAlignment="Left" Margin="10,10,0,0" Name="radTreeView1" VerticalAlignment="Top" Width="150">
    <telerik:RadTreeView.Resources>
    <Style TargetType="{x:Type telerik:RadTreeViewItem}">
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="telerik:DragDropManager.AllowDrag" Value="True"></Setter>
    </Style>
    </telerik:RadTreeView.Resources>
    <telerik:RadTreeViewItem DropPosition="Inside" Header="Item 1" />
    <telerik:RadTreeViewItem DropPosition="Inside" Header="Item 2" />
    <telerik:RadTreeViewItem DropPosition="Inside" Header="Item 3" />
    <telerik:RadTreeViewItem DropPosition="Inside" Header="Item 4" />
    <telerik:RadTreeViewItem DropPosition="Inside" Header="Item 5" />
    </telerik:RadTreeView>
    <ListBox Height="287" HorizontalAlignment="Left" Margin="166,12,0,0" Name="listBox1" VerticalAlignment="Top" Width="134" />
    </Grid>
    </Window>


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;

    using Telerik.Windows.Controls;
    using Telerik.Windows.DragDrop;

    namespace TelerikWpfApplication
    {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
    public MainWindow()
    {
    InitializeComponent();

    DragDropManager.AddDragInitializeHandler(radTreeView1, OnDragInitialize, true);
    DragDropManager.AddDragEnterHandler(radTreeView1, OnDragEnter, true);
    DragDropManager.AddDropHandler(radTreeView1, OnDrop, true);
    }

    private void OnDragInitialize(object sender, DragInitializeEventArgs e)
    {
    // get zone
    RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;
    object data = item.Item;

    e.AllowedEffects = DragDropEffects.Move;
    }

    private void OnDragEnter(object sender, Telerik.Windows.DragDrop.DragEventArgs args)
    {

    }

    private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs args)
    {
    listBox1.Items.Add("Dropped to: " + args.Source.ToString());
    }
    }
    }
  2. Voltz
    Voltz avatar
    17 posts
    Member since:
    Aug 2011

    Posted 27 Aug 2013 Link to this post

    same issue here. we moved to v2013.2.611.40 and my custom drag cues stopped working. 
  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 28 Aug 2013 Link to this post

    Hello Dušan,

    Thank you for contacting us on this matter. With the help of the provided code I managed to get to the bottom of the reported behavior. I can see that you subscribe to the events of the DragDropManager and you perform custom operations in the handlers.

    Please note that in the past our RadTreeView control was using the RadDragAndDropManager which now is obsolete and fully replaced by the DragDropManager. This is why, recently we changed the default drag and drop logic of the RadTreeView control to use the new manager. You need to have in mind that with the current release you can choose which manager to use but please note that we highly recommend to our clients to migrate to the new drag and drop logic.

    If you set the attached property telerik:TreeViewSettings.DragDropExecutionMode of  the RadTreeView control to New, you will configure the control to use the DragDropManager. Furthermore, you will need to set the IsDragDropEnabled property to True in order to get advantage of the new and improved drag and drop logic. Also, you don't need to set the telerik:DragDropManager.AllowDrag property of the RadTreeViewItems to True as we internally allow the items to be dragged.

    Please try to configure the RadTreeView control like the code below and let me know if you need any further assistance.

    <telerik:RadTreeView Name="radTreeView1"
                   Width="150"
                   IsDragDropEnabled="True"
                   Height="250"
                   Margin="10,10,0,0"
                   telerik:TreeViewSettings.DragDropExecutionMode="New"
                   HorizontalAlignment="Left"
                   VerticalAlignment="Top">
     ....
    </telerik:RadTreeView>

    @Voltz
    I can not be sure about your implementation but still you can try the same approach in your case. If your implementation is somehow different, I will need to take a look at your code to make a proper suggestion. Please try to reproduce the behavior that you report in a separate project and send it over. By doing so I will be able to fully understand your scenario and further investigate the reasons behind that behavior.

    Regards,
    Pavel R. Pavlov
    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 >>
  5. Voltz
    Voltz avatar
    17 posts
    Member since:
    Aug 2011

    Posted 28 Aug 2013 Link to this post

    Hi Pavel,

    We are using the same code

    IsDragDropEnabled="True"
    telerik:TreeViewSettings.DragDropExecutionMode="New"

    to enable drag and drop. Right now I have disabled my custom behavior to create custom visual cues but it is not working. Apparently, I am experiencing this when I apply StyleManager.ApplicationTheme = new Windows7Theme(); to the whole application. Once I comment this out, the visual cues appear.

    Please note we are using a prism desktop application and we have just updated all references to the new binaries.

    Thanks!
  6. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 30 Aug 2013 Link to this post

    Hi Voltz,

    Can you please elaborate more on your scenario. What you mean when you say "it is not working"? What you expect to be visualized and what is currently visualized? Also, how you try to create custom visual cues? Which version of our dlls you use?

    Is it possible for you to send over a project where I can see the reported behavior. If you do so I will be able to fully understand your scenario and further investigate the reasons behind the reported behavior. As our customer you can start a new support thread from your Telerik account and you will be able to attach your project in.

    Thank you for your cooperation.

    Regards,
    Pavel R. Pavlov
    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 >>
  7. Dušan
    Dušan avatar
    8 posts
    Member since:
    Oct 2012

    Posted 17 Sep 2013 Link to this post

    Greetings Pavel,

    sorry for late response. I was working on issues with higher priority. I have tried your solution and now drag & drop of your application is working again. But there is a little problem. Our previous behavior implemented that checking mechanism to decide whether drop operation is enabled or not on current tree node. This was implemented in the method
    DragDropManager.AddDragOverHandler(rtvZones, OnDragOver, true);
    ....
     
    private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs args)
    {
        args.Effects = CanDrop() ? DragDropEffects.Move : DragDropEffects.None;
        args.Handled = true;
    }
    This would ensure that if drop was not possible then default icon with (circle crossed by line) would appear. Now it is not showing. It is just minor issue now when the bigger one was solved by your suggestion but I would still like to solve this one too.

    Thank you for your response.
    Dusan Hudecek
  8. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 20 Sep 2013 Link to this post

    Hi Dušan,

    With the improved drag and drop logic we exposed the TreeViewDragDropOptions object. This object contains properties that control the visual cue of the RadTreeView control. In your case you can set the DropAction property to DropAction.None. You can access this object like this:

    private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
    {
        var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
        options.DropAction = /*Your custom logic*/
    }

    Please give this approach a try and let me know if you need any further assistance.

    Regards,
    Pavel R. Pavlov
    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 >>
  9. Dušan
    Dušan avatar
    8 posts
    Member since:
    Oct 2012

    Posted 20 Sep 2013 Link to this post

    Greetings Pavel,

    I have tried your approach but without success. I read about it on telerik web tutorial and the problem is that if I try to access instance of TreeViewDragDropOptions like this:
    var data = DragDropPayloadManager.GetDataFromObject(args.Data, TreeViewDragDropOptions.Key);
    it returns null object. I have upgraded to your latest Rad WFP Controls (version 2013.2.724.40) and it stil returns null. :(
    Do you have any suggestion why?

    thank you for your reply.
    Dusan Hudecek
  10. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 25 Sep 2013 Link to this post

    Hi Dusan,

    I am not sure how you try to subscribe to the DragOver event. Could you please change the code of the attached project so that the issue can be reproduced and send it over. By doing so we will be able to further investigate the possible reasons behind the reported behavior.

    Thank you for your cooperation.

    Regards,
    Pavel R. Pavlov
    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 >>
  11. Dušan
    Dušan avatar
    8 posts
    Member since:
    Oct 2012

    Posted 03 Oct 2013 Link to this post

    Greetings Pavel, 

     I have found what the problem with the key being null was. It look that it occured because I have used "Data" property on the instance of DragInitializeEventArgs. Then in AddDragOverHandler method I could not get data for "key". So now I do not set "Data" and I can get data for "key". I am trying to change our funcionality to your new Drag & Drop logic. So main main problem is solved I think.
    On small is that if I try to set mine datatemplate for drag & drop tooltip it does not work.
    I am not sure why. :( Thi is the last problem I have with drag & drop.

    Here is method for drag & drop initialization.
    private void OnDragInitialize(object sender, DragInitializeEventArgs e)
         {
             // These lines will "corrupt" TreeViewDragDropOptions. When DragOver occurs we cannot get options from payload manager.
             // BECAUSE IT IS OLD LOGIC OD DRAG AND DROP?
             bool corrupt = false;
             if (corrupt)
             {
                 e.AllowedEffects = DragDropEffects.Move;
                 e.DragVisual = "Test Visual Object";
                 e.DragVisualOffset = new Point(0, 0);
     
                 var payload = DragDropPayloadManager.GeneratePayload(null);
                 payload.SetData("data", "This are my data");
                 e.Data = payload;
             }
             else // Trying to use new logic.
             {
                 var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
                 var dragVisual = options.DragVisual as TreeViewDragVisual;
                 DataTemplate template = Resources["DragItemTemplate"] as DataTemplate;
                 dragVisual.ContentTemplate = template; // nothing is shown
                 dragVisual.DropTargetTemplate = template; // nothing is shown
                 options.UpdateDragVisual();
             }
         }

    And here data template in the mainwindow.xaml.
    <Window.Resources>
            <DataTemplate x:Key="DragItemTemplate">
                <TextBlock Text="This is text showing during dragging." />
            </DataTemplate>
    </Window.Resources>

    These are only modifications I have made to your project. I would send it but I can only add image attachement to your forum.

    Thanks for your reply.
    Dusan Hudecek
  12. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 07 Oct 2013 Link to this post

    Hello,

    As far as I understand you need to completely change the template of the DragVisual. You can achieve your requirement by creating a new ContenControl and setting your custom DataTemplate as ContentTempltate to that new ContentControl. You can find more information about the DragVisual in this article.

    Basically in such cases you don't need the default implementation, hence you are able to change the e.DragVisual property. You can something similar to this:

    private void OnDragInitialize(object sender, DragInitializeEventArgs e)
    {
    e.DragVisual = new ContentControl() { ContentTemplate = App.Current.Resources["DragItemTemplate"] as DataTemplate, Content = "Custom Content" };
    }
    And you can define your custom DataTemplate like this:

    <Window.Resources>
        <DataTemplate x:Key="DragItemTemplate">
            <TextBlock Text="{Binding .}" />
        </DataTemplate>
    </Window.Resources>
    Please give this approach a try and let me know if you need any further assistance.

    Regards,
    Pavel R. Pavlov
    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 >>
  13. Dušan
    Dušan avatar
    8 posts
    Member since:
    Oct 2012

    Posted 07 Oct 2013 Link to this post

    Greetings Pavel,

    I am using this approach you mentioned already. It is working without problem. I just thought that if I should use the new behavior TreeViewDragDropOptions that I should use the properties  ContentTemplate, DropTargetTemplate  of the TreeViewDragVisual object. But that din't work.
    I had to make some modifications to my logic but all is working now.

    Thank you for your help.
    Dusan Hudecek
Back to Top
UI for WPF is Visual Studio 2017 Ready