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

Deny drop based on data in viewmodel

3 Answers 78 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Ramon
Top achievements
Rank 1
Ramon asked on 16 Nov 2017, 08:21 AM

Hi all,

we are trying out Telerik drag and drop. We want to drag between 2x itemslist and a DockPanel. To be able to use Telerik drag visualizer we converted both the itemslist to a ListBox (not 100% what we wanted though, because listbox looks different).
This way we get a 'shadow' of the item we drag during the dragging. And an arrow indicating we can move the item (or red circle if denied).

The problem now is we want to deny certain drops in the dockpanel based on the data in our viewmodel. How can we accomplish this?
I can catch the events of the dockpanel like OnElementDragEnter, but I cannot set the e.Effects property to none. Also I don't have options class in my e.data object (like in your treeview example).

Also tried to set the dockpanel.allowdrop to false during drag. That works, but then the next time the drag over event wont fire again :(.

(the way we did this before Telerik components was just set the DragDropEffects.Effects to DragDropEffects.None)

 

Thanks in advance

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 20 Nov 2017, 05:09 PM
Hello Ramon,

Thank you for the detailed description of your setup.

Speaking generally, you can disable dropping a given item by implementing a custom ListBoxDragDropBehavior. By overriding its CanDrop method you should be able to manipulate whether a given element can be dropped or not. Can you please check this out?

In case further assistance is needed, feel free to approach me.

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Ramon
Top achievements
Rank 1
answered on 21 Nov 2017, 06:46 AM

hi Stefam,

 

thanks for your answer. How can i apply such a behaviour to a dockpanel? I cannot find any example for this scenario. 
Or am i forced to rewrite my code to a ListBox instead of a DockPanel?

Thanks in advance.

 

0
Stefan
Telerik team
answered on 23 Nov 2017, 02:57 PM
Hi Ramon,

As RadListBox's DragDropManager accepts only a ListBoxDragDropBehavior, dropping on RadDocking would not be possible with it. Please, excuse me for misguiding you. In order to achieve your goal, you can subscribe to the events of DragDropManager. For example, you can use the DragOver one and set the DragDropEffects through the Effects property of the event arguments to None. Then you can set the Handled property to true and terminate the execution of the event handler through a return statement. Can you please check it out?

I hope you find this helpful. Of course, feel free to update me should you need further assistance with the implementation.

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
DragAndDrop
Asked by
Ramon
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Ramon
Top achievements
Rank 1
Share this question
or