TreeViewDragCue.DragActionContentTemplate has no effect?

6 posts, 1 answers
  1. Chris
    Chris avatar
    9 posts
    Member since:
    Sep 2011

    Posted 28 Sep 2011 Link to this post

    Hi,

    I am handling a RadTreeView DropQueryEvent to try and change the text on the drag action cue depending on which key is pressed. However, the cue does not change using the code below - is my code correct?

    Thanks,
    Chris
    private void TreeView_DropQuery(object sender, DragDropQueryEventArgs e)
    {
        var source = e.Options.Source as RadTreeViewItem;
        var cue = e.Options.DragCue as TreeViewDragCue;
     
        if (e.Options.Status == DragStatus.DropDestinationQuery && otherlogic(removed))
        {
            var destination = e.Options.Destination as RadTreeViewItem;
            if (destination != null &&
                destination.DropPosition == DropPosition.Inside &&
                otherlogic(removed))
            {
                cue.DragActionContent = "Show this text! ";
                e.QueryResult = true;
            }
            else
            {
                // Cannot drag here.
                e.QueryResult = false;
                cue.DragActionContent = String.Empty;
            }
        }
        else
        {
            e.QueryResult = false;
            cue.DragActionContent = String.Empty;
        }
     
        e.Handled = true;
    }
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 03 Oct 2011 Link to this post

    Hi Chris,

     We cannot see something unusual from your code if we use this documentation article as a starting point. But we are also not aware of your scenario, how your tree is populated and what the "otherlogic" method does. Is it possible for you to send us more from your code so that we could investigate this deeper? Thank you in advance for your cooperation. 

    Regards,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Chris
    Chris avatar
    9 posts
    Member since:
    Sep 2011

    Posted 03 Oct 2011 Link to this post

    Hi,

    I can prepare a sample if you like but first I'd like to clarify my post.
    The "otherlogic" method can be ignored - that's where I do other custom boolean logic on my data.

    In the code I posted my problem is that unless I set e.QueryResult to false my custom drag cue is not shown. So it works for denying a drag (as in your documentation example) but not when affirming the user action (in my code the "Show this text" part).

    Should this be possible? If so I'll make a demo of my scenario.

    Thanks,
    Chris.
  5. Chris
    Chris avatar
    9 posts
    Member since:
    Sep 2011

    Posted 05 Oct 2011 Link to this post

    Hi,

    Here is some more code to illustrate the problem. To re-iterate my issue, I would like to set the drag cue when a drop is possible as well as when it is not. In my sample code only the "can't drop here" cue is used when a drag is not possible.

    Thanks,
    Chris.

    MainPage.xaml
    <UserControl x:Class="TreeViewDragCueTest.MainPage"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
     
        <Grid x:Name="LayoutRoot" Background="White">
             
            <telerik:RadTreeView x:Name="TreeView" Margin="8"
                                 IsExpandOnDblClickEnabled="True"
                                 IsDragDropEnabled="True"
                                 IsEditable="True"
                                 IsLineEnabled="False">
                 
                <telerik:RadTreeViewItem Header="Root">
                     
                    <telerik:RadTreeViewItem Header="Branch 1">
                        <telerik:RadTreeViewItem Header="Yes" />
                        <telerik:RadTreeViewItem Header="No" />
                        <telerik:RadTreeViewItem Header="Yes" />
                        <telerik:RadTreeViewItem Header="No" />
                        <telerik:RadTreeViewItem Header="Yes" />
                    </telerik:RadTreeViewItem>
     
                    <telerik:RadTreeViewItem Header="Branch 2">
                        <telerik:RadTreeViewItem Header="Yes" />
                        <telerik:RadTreeViewItem Header="No" />
                        <telerik:RadTreeViewItem Header="Yes" />
                        <telerik:RadTreeViewItem Header="No" />
                        <telerik:RadTreeViewItem Header="Yes" />
                    </telerik:RadTreeViewItem>
     
                    <telerik:RadTreeViewItem Header="Branch 3">
                        <telerik:RadTreeViewItem Header="Yes" />
                        <telerik:RadTreeViewItem Header="No" />
                        <telerik:RadTreeViewItem Header="Yes" />
                        <telerik:RadTreeViewItem Header="No" />
                        <telerik:RadTreeViewItem Header="Yes" />
                    </telerik:RadTreeViewItem>
                     
                </telerik:RadTreeViewItem>
     
            </telerik:RadTreeView>
        </Grid>
    </UserControl>

    MainPage.xaml.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Telerik.Windows;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.DragDrop;
    using Telerik.Windows.Controls.TreeView;
     
    namespace TreeViewDragCueTest
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
     
                TreeView.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(TreeView_DropQuery), true);
            }
     
            private void TreeView_DropQuery(object sender, DragDropQueryEventArgs e)
            {
                var source = e.Options.Source as RadTreeViewItem;
                var cue = e.Options.DragCue as TreeViewDragCue;
     
                if (e.Options.Status == DragStatus.DropDestinationQuery)
                {
                    var destination = e.Options.Destination as RadTreeViewItem;
                    if (destination.Header.ToString() == "Yes")
                    {
                        cue.DragActionContent = "Can drop here!";
                        e.QueryResult = true;
                    }
                    else
                    {
                        // Cannot drag here.
                        cue.DragActionContent = "Can't drop here!";
                        e.QueryResult = false;
                    }
                }
            }
        }
    }


  6. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 06 Oct 2011 Link to this post

    Hi Chris,

     You have to use both DropQuery and DropInfo events because the destination item also sets the dragcue during the D'N'D process. You can examine the project where your requirement is implemented. Please let us know if you need further assistance.

    All the best,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  7. Chris
    Chris avatar
    9 posts
    Member since:
    Sep 2011

    Posted 10 Oct 2011 Link to this post

    Hi,

    This works great, thanks for the help.

    Chris.
Back to Top
DevCraft banner