所以我有一个 ListView
,其中包含 MyFiles
和 MyFolders
的列表,这两个类都实现了我的界面 IExplorerItem
现在我已经设置了我的列表视图,以便我可以像这样拖放到它上面:
<ListView ItemsSource="{Binding DisplayedItems}" AllowDrop="True">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Drop">
<Command:EventToCommand Command="{Binding DropFiles}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ListView>
和命令是:
private RelayCommand<DragEventArgs> _dropFiles;
/// <summary>
/// Gets the DropFiles.
/// </summary>
public RelayCommand<DragEventArgs> DropFiles
{
get
{
return _dropFiles
?? (_dropFiles = new RelayCommand<DragEventArgs>(
args =>
{
if (args.Data.GetDataPresent(DataFormats.FileDrop))
{
// Note that you can have more than one file.
string[] files = (string[])args.Data.GetData(DataFormats.FileDrop);
//do my thing with my files
}
}
}
}
所以这适用于拖放文件和处理它们 . 但是我不想检测文件丢弃的项目 .
例如如果它被删除 IExplorerItem
是一个 MyFolder
对象,然后将它们添加到该文件夹 . 这可能吗?
1 回答
知道了,所以在我的
RelayCommand
中,我只需要深入了解DragEventArgs
类 .