c# - 在 WPF 中检测拖放文件?

标签 c# wpf .net-3.5 drag-and-drop

是否可以让 WPF 窗口/元素检测从 C# .Net 3.5 中的 Windows 资源管理器拖放文件?我找到了适用于 WinForms 的解决方案,但没有找到适用于 WPF 的解决方案。

最佳答案

尝试以下操作:

    private void MessageTextBox_Drop(object sender, DragEventArgs e)
    {
        if (e.Data is DataObject && ((DataObject)e.Data).ContainsFileDropList())
        {
            foreach (string filePath in ((DataObject)e.Data).GetFileDropList())
            {
                // Processing here     
            }
        }
    }


    private void MessageTextBox_PreviewDragEnter(object sender, DragEventArgs e)
    {
        var dropPossible = e.Data != null && ((DataObject)e.Data).ContainsFileDropList();
        if (dropPossible)
        {
            e.Effects = DragDropEffects.Copy;
        }
    }

    private void MessageTextBox_PreviewDragOver(object sender, DragEventArgs e)
    {
        e.Handled = true;
    }

关于c# - 在 WPF 中检测拖放文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/332859/

相关文章:

c# - 如何在 xamarin 表单中设置 MasterDetailPage 的宽度

wpf - WPF 和 Powershell 的键盘快捷键

.net - WPF 数据网格样式

c# - 维护 asp.net 页面的状态

c# - 如何在 Windows Mobile 中为 WM_DEVICECHANGE 消息注册表单

c# - 在我们的.net项目中更改MSBuild工具集(ToolsVersion)有什么缺点?

c# - WP 8.1 ISupportIncrementalLoading LoadMoreItemsAsync 不断被调用

c# - DateTime.ToString ("T") 和 DateTime.ToString ("G") 中的错误?

c# - HierachicalDataTemplate 和带有 ItemsControl 的 DataTemplate 之间的区别

.net - 使用带有字符串键和不区分大小写的搜索的哈希表/字典