This is a migrated thread and some comments may be shown as answers.

Cannot Drag Item from RadTreeView to Image

1 Answer 82 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Justin Young
Top achievements
Rank 1
Justin Young asked on 15 Mar 2010, 10:57 PM
I am attempting to drag a RadTreeViewItem from a RadTreeView to an Image. I've recreated the problem in a clean solution and will include the XAML and CS below. My issue is, when I am dragging the RadTreeViewItem "Drag Me" (x:Name="draggable") over the RadTreeViewItem "Drop Me" (x:Name="droppable") I get an informative DragCue which shows my item and indicates that I am able to "Drop in Drop Me". Upon dropping the item, the treeview's DragEnded event is fired and I can perform any logic required there.
When I try to drag "Drag Me" over the Image (x:Name="droppableImage"), a block (red circle with slash) appears next to the item and when I drop it, the DragEnded event does not fire. The OnDropQuery event does fire upon hovering over the image, however setting e.QueryResult = true does not alter the behavior. Anyhow, the code below should be fairly self explanatory.

Thanks in advance.

MainPage.xaml
-------------------------------------------------------------------------------------------------------
<UserControl x:Class="TestDrag.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" xmlns:DragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls"  
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
  <Grid x:Name="LayoutRoot"
        <Image x:Name="droppableImage" Source="check.png" DragDrop:RadDragAndDropManager.AllowDrop="True" /> 
        <Controls:RadTreeView x:Name="treeView" IsDragDropEnabled="True" BorderBrush="Black" BorderThickness="1"
            <Controls:RadTreeView.Items> 
                <Controls:RadTreeViewItem x:Name="droppable" Header="Drop Me" IsDropAllowed="True" /> 
                <Controls:RadTreeViewItem x:Name="draggable" Header="Drag Me" IsDropAllowed="False" /> 
            </Controls:RadTreeView.Items> 
        </Controls:RadTreeView> 
    </Grid> 
</UserControl> 
 

-------------------------------------------------------------------------------------------------------

MainPage.xaml.cs
-------------------------------------------------------------------------------------------------------
namespace TestDrag { 
    public partial class MainPage : UserControl { 
        public MainPage() { 
            InitializeComponent(); 
 
            treeView.DragEnded += treeView_DragEnded; 
            treeView.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDropQuery), true); 
            draggable.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDropQuery), true); 
        } 
 
        private void treeView_DragEnded(object sender, RadTreeViewDragEndedEventArgs e) { 
            if (e.TargetDropItem != null && e.DraggedItems.Count == 1) { 
                RadWindow.Alert("DragEnded fired."); 
            } 
        } 
 
        private void OnDropQuery(object sender, DragDropQueryEventArgs e) { 
            if (e.Options.Destination is RadTreeViewItem) { 
                var treeViewItem = (RadTreeViewItem)e.Options.Destination; 
                if (treeViewItem.DropPosition != DropPosition.Inside) { 
                    e.QueryResult = false
                } 
            } else if (e.Options.Destination is Image) { 
                e.QueryResult = true
                e.Handled = true
            } 
        } 
    } 

1 Answer, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 19 Mar 2010, 02:18 PM
Hello Justin Young,

I am sorry for the delayed reply!

Yes, the visual that appears during DragDrop is a TreeViewDragCue obejct. It can be accessed by the e.Options.DragCue property. There you can assign a drag action / tooltip / items.

The icon is controlled by the IsDropPossible property. I modified your code to do this, you can see the attached project.

Best wishes,
Miroslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
TreeView
Asked by
Justin Young
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Share this question
or