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

DropQuery not being fired anymore (TreeViewItem)

4 Answers 98 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Doug
Top achievements
Rank 1
Doug asked on 24 Jan 2012, 05:31 PM
Hello, I've been using 2011 Q2 09.20 hotfix version of radcontrols for silverlight.  I'd like to upgrade but have been unable to do so because of issues with drag/drop with all versions released since.

I have a radtreeview that I want to allow dropping items from different sources onto specific tree items.  As I mentioned this works fine in 2011 Q2 09.20 but not in later versions.  The problem with the later versions appears to be that the DropQuery event is fired for the treeview, but not for the specific treeviewitems.  Below is my code:
XAML:
<telerik:RadTreeView x:Name="rtvTags"
                     Grid.Row="1"
                     ItemTemplateSelector="{StaticResource TagTemplateSelector}"
                     ItemsSource="{Binding Items}"
                     PreviewExpanded="rtvTags_PreviewExpanded"
                     ScrollViewer.VerticalScrollBarVisibility="Auto"
                     ScrollViewer.HorizontalScrollBarVisibility="Auto"
                     AllowDrop="True"
                     telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}"
                     IsVirtualizing="True">

Code behind:
   public partial class DocumentTagsView : ReviewView
    {
        public DocumentTagsView()
        {
 
            InitializeComponent();
             
            RadDragAndDropManager.AddDropInfoHandler(rtvTags, Tags_DropInfo);
            RadDragAndDropManager.AddDropQueryHandler(rtvTags, Tags_DropQuery);
            rtvTags.MouseLeave += (s, ea) =>
                {
                    ViewModel.ResetIsDropTarget();
                };
 
        }
        private void Tags_DropQuery(object sender, DragDropQueryEventArgs e)
        {
            e.QueryResult = false;
            ViewModel.ResetIsDropTarget();
            if (e.Options.Payload is IList<IDSDocument> |
                e.Options.Payload is IList<IDSSearch> |
                e.Options.Payload is IList<SavedSearchItem>)
            {
                DocTagItem item = e.Options.Destination.DataContext as DocTagItem;
                if (item != null)
                {
                    e.QueryResult = item.CanBulkTag;
                    item.IsDropTarget = true;
                    e.Handled = true;
                }               
            }       
        }
}

Thanks

Doug

4 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 26 Jan 2012, 01:26 PM
Hello Doug,

Have you tried setting the TreeViews property IsDragDropEnabled to true?
The reason that this is occurring is that the TreeView is using the DragQuery handler, for the internal use of the RadDragAndDropManager. 
This change has been introduced because of our new DragDrop mechanism. The DragDropManager, which provides more intuitive API and allows the developer to create more complex drag and drop scenarios. You can read more about it here.

Hope this helps!

Regards,
Nik
the Telerik team

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

0
Doug
Top achievements
Rank 1
answered on 27 Jan 2012, 03:51 PM
Thanks for the response.  I do not want to set IsDragDropEnabled to true because then the built in treeview drag/drop logic is used. 

In this scenario I am not actually adding items to the tree view -  I am performing actions based on which item it is dropped onto.  Also whether or not a drop is allowed depends on the specific item it is dragged over.  From the code (again):

DocTagItem item = e.Options.Destination.DataContext as DocTagItem;
if (item != null)
{
e.QueryResult = item.CanBulkTag;
item.IsDropTarget = true;
e.Handled = true;
}

The property CanBulkTag tells it whether a drop can happen on a specific item.  IsDropTarget is a property I use to add a border around the item to indicate it's the drop target.  Attached is a screenshot of how it works (correctly) in 2011 Q2 09.20 release. 

As I said in releases since then the DropQuery doesn't get called for specific items of the tree, only for the tree itself.  it is the first 2 lines of code that I can tell that from, in the later versions the criteria for the if statement is never met because e.Options.Destination is never a treeviewitem.

I saw and read and tried using the new DragDrop framework without any luck.  I am having a hard time finding the equivalents in the new framework and there's currently not much sample code.  The new framework isn't the issue though (I don't think), as it was already available in 2011 Q2 09.20 version. 

Thanks

Doug

0
Nick
Telerik team
answered on 31 Jan 2012, 01:00 PM
Hello Doug,

Unfortunately, the only other workaround that we can propose would be to subscribe to the ItemPrepared event, and set the AllowDrag property there. 
private void TreeViewItemPrepared(object sender, RadTreeViewItemPreparedEventArgs e)
        {
            RadDragAndDropManager.SetAllowDrag(e.PreparedItem, true);
        }

Hope this helps! 

All the best,
Nik
the Telerik team

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

0
Doug
Top achievements
Rank 1
answered on 02 Feb 2012, 10:40 PM
Thanks, it does seem to work now (though it was SetAllowDrop that I had to call in the ItemPrepared event). 

Doug
Tags
DragAndDrop
Asked by
Doug
Top achievements
Rank 1
Answers by
Nick
Telerik team
Doug
Top achievements
Rank 1
Share this question
or