如何使用 gong 在 WPF 中创建多个 DropHandler?

How to create several DropHandlers in WPF using gong?

我在我的项目中使用 Gong Framework
我创建了以下 DropHandler。
Xaml:

<ListBox ItemsSource="{Binding Collection}" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}"/>

视图模型:

class MyViewModel : IDropTarget
{
    ObservableCollection<SomeType> Collection;

    public void DragOver(IDropInfo dropInfo)
    {
        // ...
    }

    public void Drop(IDropInfo dropInfo)
    {
        // ...
    }
}

问题。 我想在这个 window 中和另一个 ListBox 的另一个 DropHandler。但是我不知道,我该怎么做。如何再次实现接口 IDropTarget

您不能在同一个 class 中实现接口 "again" 但您可以将 DropHandler 属性 绑定到 IDropTarget 属性 视图模型:

dd:DragDrop.DropHandler="{Binding FirstDropTarget}"

然后您将创建一个新的 class 来处理删除。如果您需要对视图模型的引用,您可以将其注入 IDropTarget 实现,例如:

class MyViewModel
{
    ObservableCollection<SomeType> Collection;

    public MyViewModel()
    {
        FirstDropTarget = new YourHandler(this);
        SecondDropTarget = new YourOtherHandler(this);
    }

    public IDropTarget FirstDropTarget { get; }
    public IDropTarget SecondDropTarget { get; }
}