c# - 如何使用锣在WPF中创建几个DropHandlers?
问题描述
我在我的项目中使用了一个龚框架。
我创建了以下 DropHandler。
xml:
<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)
{
// ...
}
}
问题。我想和另一个 DropHandlerListBox
在这个窗口中为另一个。但我不知道,我该怎么做。如何IDropTarget
再次实现接口?
解决方案
您不能在同一个类中“再次”实现接口,但可以将DropHandler
属性绑定到IDropTarget
视图模型的属性:
dd:DragDrop.DropHandler="{Binding FirstDropTarget}"
然后,您将创建一个新类来处理丢弃。如果您需要对视图模型的引用,您可以将其注入到IDropTarget
实现中,例如:
class MyViewModel
{
ObservableCollection<SomeType> Collection;
public MyViewModel()
{
FirstDropTarget = new YourHandler(this);
SecondDropTarget = new YourOtherHandler(this);
}
public IDropTarget FirstDropTarget { get; }
public IDropTarget SecondDropTarget { get; }
}
推荐阅读
- ios - 推送通知在 iOS 中随机删除
- reactjs - 验证后如何重定向到另一个页面?并且还想将值传递到下一页
- python - 使用公共密钥在数据帧上广播系列乘法
- node.js - 连接到通过 IPv4 运行的服务器时出现长时间延迟
- excel - 如何检查单元格是否包含多个值之一,如果这些列都包含任一值,则如何更改另一个单元格
- html - 在同一段落中为罗马和斜体文本使用不同大小的字体
- ios - 在用户的文档文件夹中创建一个新的子文件夹会创建一个文件
- node.js - Discord Music 机器人随机抛出此错误,显然没有挑衅
- python - 递归生成器说明
- reactjs - 如何部署具有代码拆分功能的 JS 应用程序,确保过去的应用程序版本不会中断