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

DragDropBehavior not bindable, should inherit from FrameworkElement

3 Answers 130 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
jstevenson72
Top achievements
Rank 1
jstevenson72 asked on 04 Apr 2013, 02:51 PM
I am trying to create a universal Behavior for my application for DragNDrop using your infrastructure.

I would like to bind an items datacontext to a property of my DragDropBehavior but your abstract class inherits from DependencyObject instead of FrameworkElement so it doesn't work.

Can you change this class:
public abstract class DragDropBehavior<TState> : DependencyObject, IDragDropBehavior<TState> where TState : DragDropState

To this in the future:
public abstract class DragDropBehavior<TState> : FrameworkElement, IDragDropBehavior<TState> where TState : DragDropState

3 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 09 Apr 2013, 08:27 AM
Hi Jason,

You can accomplish that by implementing the IDragDropBehavior interface and inheriting from FrameworkElement, which should give you the functional requirements that you have. 

Let me know if you need any help doing it! 

Greetings,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
jstevenson72
Top achievements
Rank 1
answered on 09 Apr 2013, 03:36 PM
I had coded up a whole class doing just that but I couldn't figure out how to get it to work in the Xaml.

Do you have an example that shows how to apply a behavior from a Custom Class that implements IDragDropBehavior interface?

Also would I lose the built in Adorner logic, or does that come along for free?

Thanks,

Jason
0
Nick
Telerik team
answered on 10 Apr 2013, 08:23 AM
Hello Jason,

Unfortunately the Generig DragDropBehavior class cannot be used directly in XAML this is a limitation of the framework itself. To use it there you have to inherit from the generic class and use the derived class definition instead. 

As to the adorner logic, I am not sure to what you are referring exactly. Can you clarify?

Looking forward to your reply! 

Regards,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Felix
Top achievements
Rank 1
commented on 27 Mar 2025, 07:17 AM

This is a very old issue, but I'm finding myself in the same spot. Has there been any changes to the Telerik library that would make this possible now? I have a simple class derived from `ListBoxDragDropBehavior` with a DependencyProperty that I need to bind to (see the two screenshots of the basic setup below).

jstevenson72
Top achievements
Rank 1
commented on 27 Mar 2025, 11:12 AM

@Felix I ended up not using Telerik controls.  They in the long run were more trouble than they were worth.  I've been using Gong WPF Drag/Drop NuGet package for many years now, with great success.

https://github.com/punker76/gong-wpf-dragdrop
Felix
Top achievements
Rank 1
commented on 27 Mar 2025, 03:20 PM

Hi Jason, thanks for your input! I also stumbled upon the gong-wpf-dragdrop library, and it does the job just fine indeed. Because we already heavily use the Telerik controls in our code, I was hoping to find a solution based on their library, instead of having to add a new dependency. But as things are looking right now, that might be the only viable option unfortunately.
Martin Ivanov
Telerik team
commented on 28 Mar 2025, 08:15 AM | edited

Hey guys, what you are doing sounds meaningful, so I've logged a new request in our feedback portal to change the parent class of the behavior to Freezable. This will allow automatic inheritance of the data context in XAML and also the usage of ElementName binding.

Felix, in the meantime, an idea that you can explore is to manually define the binding in C#. This will allow you to set the Source of the Binding object.

 

public MainWindow()
{
    InitializeComponent();

    var behavior = (SessionItemDragDropBehavior)this.listBox.DragDropBehavior;
    var binding = new Binding(nameof(MyViewModel.DropAction)) { Source = this.DataContext };
    BindingOperations.SetBinding(behavior, SessionItemDragDropBehavior.OnDropActionProperty, binding);
}

 

I've attached a sample project showing this. I hope it helps.

Felix
Top achievements
Rank 1
commented on 28 Mar 2025, 12:51 PM

Hey Martin, I was able to get the DragDropBehavior working based on your example! It needed a bit more tinkering because we use Caliburn.Micro to manage the DataContext and binding, but I eventually got there. Thanks a lot, your work is much appreciated!
jstevenson72
Top achievements
Rank 1
commented on 28 Mar 2025, 02:04 PM

After 12 years, now they tell me, lol.  
Martin Ivanov
Telerik team
commented on 31 Mar 2025, 10:12 AM

Felix, I am glad to hear that the suggestion helped.

And Jason, I am sorry that we needed so much time to wrap our heads around the problem and log it for improvement. 
Tags
DragAndDrop
Asked by
jstevenson72
Top achievements
Rank 1
Answers by
Nick
Telerik team
jstevenson72
Top achievements
Rank 1
Share this question
or