拖放WPF C#获取文件路径 [英] Drag and drop WPF C# getting file path
本文介绍了拖放WPF C#获取文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我正在尝试将文件拖放到wpf窗口。我可以到这里,但我没有数据?我想获取文件路径,例如
C:\\folder \\ data.raw
Hi I am trying to drag and drop a file on to a wpf window. I can get to here but I no data is available? I would like to get the file path such as
C:\\folder\\data.raw
private void Window_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("FileName"))
{
string folderPath = Convert.ToString(e.Data.GetData("FileName"));
object data = e.Data.GetData(typeof(Object));
//do whatever you need to do with the folder path
}
}
AllowDrop =TrueDrop =Window_Drop
AllowDrop="True" Drop="Window_Drop"
推荐答案
这是基本上你想做什么。
Hi, This is basically what you want to do.
private void ImagePanel_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// Note that you can have more than one file.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
// Assuming you have one file that you care about, pass it off to whatever
// handling code you have defined.
HandleFileOpen(files[0]);
}
}
这篇关于拖放WPF C#获取文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文